git head and branches

origin is a local alias to a remote repository

  1. git push [origin|<URL>] <branch> pushes changes to a particular remote repository
  2. git remote
  3. git remote -v find out information about remote
  4. git remote show origin shows the origin
  5. git remote add origin <URL> sets an origin
  6. git remote rename origin <new_name> renames the origin

HEAD @ is a pointer to a branch

  1. Difference between carot and tilde

Image from paulboxley.

  1. The @ at-sign without leading branch/reference is the same as HEAD.


  1. git branch <branch name> create a branch
  2. git checkout <branch name> move HEAD to that branch
  3. git checkout -b <branch name> create branch and move HEAD to it
  4. git checkout master return to the master branch
  5. git merge <branch name> merges checked out branch (typically master) with another branch
  6. git branch -d <branch name> removes a branch
  7. git mergetool optional tool to visually merge
  8. git branch -a show all branches
  9. git branch -v see last commit
  10. git branch -vv see tracking information
  11. git branch --no-merged see the branches that have not merged with checked out branch (typically master)
  12. git diff origin/master..master show differences between local master and origin's master

Working with remote references

  1. git ls-remote
  2. git ls-remote origin master
  3. git fetch origin
  4. git remote add <remote_name>
  5. git fetch <remote_name>
  6. git push origin <branch_name> shortcut for git push origin <bn>:<bn>
  7. git merge origin/<bn> merges current working branch
  8. git checkout -b <bn> origin/<bn> create local branch <bn> based off origin/<bn>
  9. git checkout --track origin/<bn> shorthand for the above
  10. git checkout <bn> shorthand for the above if <bn> exists on origin
  11. git push origin --delete <bn> delete a remote branch


  1. git checkout -b <myworkingbranch> --track origin/master create a local branch
  2. ~git config –global alias.nb "!git checkout –track $(git config branch.$(git rev-parge –abbrev-ref HEAD).remote)/$(git rev-parse –abrev-ref HEAD) -b"~
  3. git nb foobar
  4. hub


  1. Set an alias for an alias command
git config --global alias.alias "config --get-regexp ^alias\."
  1. git alias : use the alias command
  2. Set an alias for alog
git config --global alias.alog "log --graph --oneline --all --decorate"


  1. Suppose you did the following git add -A, i.e. added all modifications
  2. git reset HEAD <file> you can unstage them individually
  3. git reset or unstage all the modifications

Undoing things

  1. fix human errors
  2. ~git commit -m "some typo"~ want to undo this commit
  3. git reset HEAD~ unstages your commit
  4. make corrections
  5. git add ... stage them
  6. git commit -c ORIG_HEAD allows you to edit the old commit message ORIG_HEAD is the original head
  7. git revert HEAD undoes a public commit
  8. nice read
  9. another stackoverflow


Comments powered by Disqus