Skip to content

Instantly share code, notes, and snippets.

@jasonrobot
Last active December 21, 2016 22:30
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 jasonrobot/2dca6bce66c16b401634938186aad1f1 to your computer and use it in GitHub Desktop.
Save jasonrobot/2dca6bce66c16b401634938186aad1f1 to your computer and use it in GitHub Desktop.
Cool git commands (some shell in there too). Alias these to stuff in your shell if you want to use them quickly.
#deletes all branches that have been merged into master (except your current branch) (substitute "master" for whatever branch you want to clean against)
git branch --merged master | grep -v "\*" | xargs -n 1 git branch -d
#you can leave off the last command to just list them
#Adds the current branch you're on to your prompt (put this in your .bashrc file)
#be sure to do `source ~/.bashrc` to load it into your current session
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
#Shows the branches you've most recently committed on, and how old they are (wow!)
#(you can change out the arg to tail to show as many lines as you want, or remove the call to tail altogether)
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' | tail -n 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment