ong-z
8/12/2016 - 8:36 AM

Git Branch Housekeeping

Git Branch Housekeeping

# Reference -- http://railsware.com/blog/2014/08/11/git-housekeeping-tutorial-clean-up-outdated-branches-in-local-and-remote-repositories/

# show information about origin
git remote show origin

# check merged/not merged local banches
git checkout master
git branch --merged (list branches merged with current branch)
git branch --no-merged (list branches not merged with current branch)

# delete branch
git branch -d {branch_name}
git branch -D {branch_name} (forced delete, probably for branches that have not been merged)

# delete remote branch
git push origin :{branch_name}
git push origin --delete {branch_name} (As of Git v1.7.0)

# clean-up outdated references
git remote prune origin

# rename local branch 
git branch -m new-name (if on current branch to rename)
git branch -m old-name new-name (if on another branch)

# delete the old-name remote branch and push the new-name local branch
git push origin :old-name new-name

# reset the upstream branch for the new-name local branch
git push origin -u new-name

# set up branch to track remote branch spring from origin
git branch --set-upstream-to origin/spring