git - Remove local branches no longer on remote -


is there simple way delete local branches not have remote equivalent?

example:

branches (local , remote)

  • master
  • origin/master
  • origin/bug-fix-a
  • origin/bug-fix-b
  • origin/bug-fix-c

locally, have master branch. need work on bug-fix-a, check out, work on it, , push changes remote. next same bug-fix-b.

branches (local , remote)

  • master
  • bug-fix-a
  • bug-fix-b
  • origin/master
  • origin/bug-fix-a
  • origin/bug-fix-b
  • origin/bug-fix-c

now have local branches master, bug-fix-a, bug-fix-b. master branch maintainer merge changes master , delete branches has merged.

so current state now:

branches (local , remote)

  • master
  • bug-fix-a
  • bug-fix-b
  • origin/master
  • origin/bug-fix-c

now call command delete branches (in case bug-fix-a, bug-fix-b), no longer represented in remote repository.

it existing command git remote prune origin, more git local prune origin.

git remote prune origin prunes tracking branches not on remote.

git branch --merged lists branches have been merged current branch.

xargs git branch -d deletes branches listed on standard input.

be careful deleting branches listed git branch --merged. list include master or other branches you'd prefer not delete.

to give opportunity edit list before deleting branches, following in 1 line:

git branch --merged >/tmp/merged-branches && vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -