Quick Use Guide
As someone who used SVN for the last decade, switching over to git was slightly confusing since the terminology is different. Hopefully, this usage guide will help.
A commit is like a snapshot of the code at a particular time in the repository. It is possible to recover code to a previous commit if something were to happen to the code (such as accidental bugs being introduced, or accidentally deleting or modifying some file).
Similar to SVN where files are included/excluded to a commit, git allows you to stage/unstage files to commit. A file that is staged will be added to the next commit that is made.
Typically, you will want to stage all files for commit which can be done by running:
$ git add -A .
git status to see all files that are staged as well as any changed but unstaged files.
$ git status
To commit all the staged files with a message:
$ git commit -m 'message'
To revert all changes in the current repository, use:
## Fetch latest from remote $ git fetch --all ## Reset all changes fetched previously. $ git reset --hard HEAD
To revert a specific file from a specific revision, use
$ git checkout <revision> <filename>
Git allows you to push/pull changes from other remote git repositories. Remote repositories can be in another path or hosted somewhere on the internet.
To see your repository's remotes:
$ git remote -v
To add a new remote:
$ git remote add origin git@gitlab-blah:user/repo.git
To remove a remote:
$ git remote rm origin
If your remote uses SSH, you will most likely need to configure SSH in order to make use of SSH key based authentication. You can read more about this at SSH Configuration File, but the basic idea is to create a SSH configuration file at
~/.ssh/config defining the remote's host.
Host gitlab-remote User git HostName git.example.com IdentityFile ~/.ssh/gitlab-remote
Pushing / Pulling
After making a new change in your repository, you may want to push your changes out to other repositories. Do so by running:
$ git push
You may also specify a specific remote and branch as well. Eg:
git push remote-name branch-name.
Conversely, to retrieve changes from another repository, run
$ git pull
After creating a new branch
development and making changes to this branch, you may want to merge the changes on the
development branch back into
development$ git merge master ## Resolve any conflicts development$ git checkout master master$ git merge --no-ff development
--no-ff flag prevents the merge from executing a fast-forward. This ensures that a new node will be constructed that records the merge event instead of a fast-forwarding on the branch.