Git Reference Guide
Introduction to Git
Git is a distributed version control system used to track changes in source code during software development.
Create a Repository
Create a New Project:
Pay special attention to the project group and visibility level.
Clone the Repository
Note: Use SSH if you have already set up SSH Credentials. Use HTTPS if you would like to use your login information (preferred on remote, less secure server environments).
Using the command line:
git clone git@gitlab.cicsnc.org:[your-repo-path-here].git
Configuration
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Basic Git Commands
git init
: Initializing a Repositorygit clone <repository_URL>
: Cloning a Repositorygit add <filename>
: Adding Changesgit add -A
: Adding ALL Changesgit commit -m "Commit Message"
: Committing changesgit status
: Checking status of current git repogit log
: Viewing Commit History
Branching and Merging
git branch <new-branch>
: create a new branch based on the current HEADgit branch <new-branch> <base-branch>
: create a new branch based on some existing onegit switch <branch-name>
: switch togit merge <branch_name>
: mergeinto current branch git branch -d <branch_name>
: delete
Remote Repositories
Remote repositories are shared locations for storing version controlled code that often allow for collaboration. Examples are GitHub and GitLab.
git remote -v
: See linked remote repositories (verbose)git remote add <remote_repository_name> <remote_URL>
: add a remote repositorygit push -u <remote_repository_name> <branch_name>
: push changes to a remote repositorygit pull <remote_repository_name> <branch_name>
: pull changes from a remote repositorygit pull <remote_repository_name> <branch_name> -a
: pull all changes from a remote repository, including new branches
Note: If you only have one remote repository called origin, you do not need to include the
; git will use origin by default in most cases.
Setting up Overleaf as an Additional Remote
It is often helpful to be able to push/pull/update content in multiple locations. This is especially important for connecting Overleaf and GitLab. For more information: Using Git and Github with Overleaf
Note: If you registered for Overleaf using your Google Account (which you probably did), you will need to set up a password on Overleaf to pull from the Overleaf repo. To do so, go to your Home screen in Overleaf, access the Account Dropdown and Reset/Change/Configure Settings.
Start a project on Overleaf. This will create a Git Repo on Overleaf’s servers.
Make sure you have an existing project on GitLab that you have cloned to your development environment. Setting up your project on GitLab then cloning it should have already set up your remote in your environment.
To confirm, run
git remote -v
. You should see your GitLab remote listed.
Add Overleaf as an additional remote. To do so, run
git remote add overleaf <YOUR OVERLEAF PROJECT GIT URL>
. You can find your Overleaf project Git URL in Overleaf by selecting the Menu button in the top right corner when you are inside the project and clicking on the Git button under the Sync subheading. Thehttps://git.overleaf.com/<project-id>
url is what you need to add your project as a remote.Double check you have added the remote correctly. To do so, run
git remote -v
. You should see both your GitLab and Overleaf remote.Pull the content from your Overleaf project to your environment. To do so, run
git pull overleaf master --allow-unrelated-histories
. This will likely generate a merge conflict and notify you accordingly. Run:q
to leave the editor.Make whatever changes and adjustments are needed on the project.
Add and commit changes. To do so, run
git add -A && git commit -m "configured project"
Push changes to GitLab. Run
git push
.Push changes to Overleaf. Run
git push overleaf main:master
.Check your Overleaf project to confirm that the changes have arrived there.
Note: You do not need to Add, Commit, or Push on Overleaf with GitLab (GitHub sync supports this). To bring changes made in Overleaf to a different environment, simply pull the Overleaf Repo to that environment:
git pull overleaf master
.