These are some very useful Git aliases that I've found to be invaluable when using Git on a day-to-day basis.
This will remove any branch from your local repo that has been merged in the remote. Useful for keeping your local copy clean.
Put this into your .bashrc
file or .bash_aliases
:
alias git-rm-merged='git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d'
This will remove any local branches that no longer exist on the remote, and has been merged.
Put this into your .bashrc
file or .bash_aliases
:
alias git-rm-orphaned="git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d"
You may also change to this method, which will force remove any branch from your local repo that isn't on the remote.
This could delete any branches you could be working on:
alias git-rm-orphaned-force="git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -D"
This is a Python port of https://github.com/aanand/git-up, which still works perfectly well, but is no longer maintained. This will stash, pull and rebase your local branches in line with their state on the remote.
Run the following commands from a terminal:
sudo -H pip3 install git-up
git config --global alias.up git-up