Learning git

This page documents steps for using git. If you haven't installed git, please see our install git page.

The social forum code is available on the server

Tips and Tricks

Regular Workflow

  • Get an update to date copy:
    git fetch
  • See what changes are in store for you
    git diff <local-branch> <remote-branch>
  • So, for example if the remote you have fetched is named "origin" (the repository from which you originally cloned, in most cases), the command would be:
    git diff master origin/master
  • Accept those changes
    git merge origin/master
  • Begin developing
  • As you complete working code, commit:
    git commit path/to/changed/file(s)
    # Or
    git add path/to/changed/files
    git commit
  • When you want to make your changes available to others
    • Get most recent version (you may get a conflict here - if so see below)
      git fetch
      git diff
      git merge origin/master
    • Push your changes
      git push

Undoing things

Sometimes we make changes in git that we want to undo.

  • Undo a changed file that has not been git added or git committed
    git checkout path/to/file
  • Undo a commit (ideally before it has been pushed). You can find the commit you want to revert by typing git log (it should be the md5 hash)
    git revert <commit>
  • Get rid of all uncommitted changes in your working directory
    git reset --hard

Dealing with conflicts

  • git will tell you which files are in conflict. Those files will contain the conflicted code enclosed in >>>> <<<<< characters.
  • Manually edit the conflicted files, choosing which code to keep and which to throw away
  • git add path/to/conflicted/files
  • git commit

Additional References

Linux or command line tutorial

Please see tutorial.


Please follow this helpful guide.

Last modified 8 years ago Last modified on 07/13/10 00:13:49