1. Install git from:

git-osx-installer for Mac OS X

2. Configure:

$git config --global user.name "Your name here"   
$git config --global user.email "yourmail@here.com"   

optional

$git config --global merge.tool vimdiff    
$git config --global core.editor vim   
$git config --global color.ui true   

3. Commands:

  • Help:
$ git help   
  • Initialization: In the project root directory execute this:
$ git init
  • Common usage:
$ git add  # add new files or modified ones to be commited
$ git commit -m "message"
  • Delete last 3 commits:
$ git reset --hard HEAD~3  
  • Undo last changes:
$ git revert  # This option creates a new commit with the last changes removed  

4. Branches

  • Create branch
$ git branch   
  • Change current branch
$ git checkout   
  • Merge two branches
$ git merge   # Merges current branch with   
  • Delete branch
$ git branch -d   

5. Tags

  • Create tag
 $ git tag   
 # The tag names can be used with other   
 # git commands like $ git checkout   

6. Remote repository

  • Configure remote repository
$ git remote add origin git@github.com:madcat/cachirulo.git  
  • Send files to remote repository
$ git push -u origin master   
  • Retrive files from remote repository
$ git pull   

7. Misc

  • Hide the current changes
$ git stash  
  • Recover last hidden changes
$ git stash pop     
  • Download all tracked branches
$ git remote update      
$ git pull --all            
  • To track a branch
$ git checkout -b localbranchName origin/remotebranchname        
  • List all branches, even those not tracked
$ git branch -a