A Quick Introduction to git
Note: This is in no way a replacement for a git tutorial. It only outlines a recommended workflow, and assumes that you already know what is a revision control system and are familiar with the basics of git.
The recommended workflow with git is as follows.
-
Create a working branch and do your edits in the branch.
$ git branch mybranch $ git checkout mybranch
- You are encouraged to commit several times locally. Unlike SVN, where the model is to create large commits, the model in git is to do several small commits. Rule of thumb: keep unrelated changes in separate commits. To encourage that, git forces you to git add any file that you want to commit, even if the file is already tracked by git. In git's terminology, this is called “staging” a file for commit.
-
Once you are satisfied, merge the branch back to the master branch.
$ git checkout master $ git merge mybranch
Use git help merge for more information. If master was not changed in between then this results in the master branch being “fast forwarded” to mybranch. If the master branch was changed in the meanwhile then a new merge commit will be created.
If you want to push your changes back to the server, then it would also be a good idea to do a git pull before doing the merge.
-
Delete the temporary branch.
$ git branch -d mybranch
-
Push back to server, if desired:
$ git push origin --all
The --all option tells git to push all the branches. If you leave out --all then only the current branch will be pushed. Note that this means that you could have your own private local branches that you do not want to make public.