Skip to content

Instantly share code, notes, and snippets.

@anildigital
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anildigital/3617c3e23225e5af35cf to your computer and use it in GitHub Desktop.
Save anildigital/3617c3e23225e5af35cf to your computer and use it in GitHub Desktop.
Useful Git commands and defaults

Show git branch name in Bash prompt

Put this line in your ~/.bashrc or ~/.bash_profile

export PS1="\h:\W \u\$(__git_ps1 \" (%s) \")\$ "

Configure shortcuts

git config --global alias.co checkout
git config --global alias.st status

Useful Git Commands

  • Go back to last Git branch
git checkout -    
  • Add changes to git hunk by hunk
git add - p
  • Search branch name for Git commit hash id
git branch --contains <sha_commit_id>
  • Prune remote branch
git remote prune origin 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment