Quick-start Guide to git

The normal (recommended) workflow on git is:

  1. Create a working branch and do your edits in the branch.

    $ git branch mybranch
    $ git checkout mybranch
  2. 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.
  3. 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 the master wasn't 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.

  4. Delete the temporary branch.

    $ git branch -d mybranch
  5. 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.

The entire repository history can be visualized in ASCII art with git log --graph. On Linux and OS X you can also do gitk --all to visualize the history graphically. (There must be a similar utility for Windows version of git.) The --all option tells gitk to visualize all branches.