Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save kudosqujo/ee5c30926a0335066526840d2a9c26fe to your computer and use it in GitHub Desktop.

Select an option

Save kudosqujo/ee5c30926a0335066526840d2a9c26fe to your computer and use it in GitHub Desktop.
[Tidy up Git branches] Delete & prune local/remote branches #git
# Delete remote branches that have been merged into 'origin/develop' (besides current, 'origin/develop' and 'origin/master')
git pull --rebase upstream develop:develop
git push origin develop:develop
git remote prune origin
git branch -r --merged origin/develop | grep -wv 'master\|develop' | sed 's/^origin\///' | xargs -n 1 git push -d origin
git remote prune origin
# Delete local branches that have been merged into 'develop' (besides current, 'develop' and 'master' branches)
git branch --merged develop | grep -wv '\*\|master\|develop' | xargs -n 1 git branch -d
git push origin -d LOCAL_BRANCH # remove remote branch tracked by local branch
git remote prune origin # remove *references* (refs/remotes/…) for remote branches
# that no longer exist (run `git branch -a` before and after
# to see the difference.
git branch -d LOCAL_BRANCH # remove branch locally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment