Skip to content

Instantly share code, notes, and snippets.

@dvonlehman
Last active July 6, 2020 18:58
Show Gist options
  • Save dvonlehman/4705744efdbe192cddd2eacc3aa21709 to your computer and use it in GitHub Desktop.
Save dvonlehman/4705744efdbe192cddd2eacc3aa21709 to your computer and use it in GitHub Desktop.
Some handy custom git shell commands
# Add these functions to your shell profile, i.e. ~/.bash_profile or ~/.zshrc
# Delete local branches that no longer exist in the remote
function git-branch-cleanup {
git fetch -p && for branch in `git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'`; do git branch -D $branch; done
}
# Display the branches in the order you last worked on them
# https://stackoverflow.com/a/2514279/446542
function git-branch-history {
for k in `git branch | sed s/^..//`; do echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k --`\\t"$k";done | sort
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment