Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 1
    Thanks, first command worked for me. You can also fetch only one branch with git fetch origin branchname or create an alias like ft = "!f() { git fetch origin $(git rev-parse --abbrev-ref HEAD);}; f" to fetch only the current branch (my personal favorite). Cheers. Commented May 31, 2018 at 21:17
  • Maybe OT but what does the -r flag means? I see xargs has a -R argument but didn't find anything about -r. I mean, in theory if I remember correctly how xargs works, even without -r it should work. Commented Jan 11, 2019 at 12:17
  • I like this answer. A couple of notes (stating the obvious really). It's possible to "preview" which branches are going to be deleted by removing the last pipe and last command | xargs git branch -d. Also, by removing the -r option (--remotes) from git branch -d we only clean the local branches (which may be enough considering that by default git branch doesn't show remote branches anyway). Commented Jan 11, 2019 at 12:18
  • Thanks! This was exactly what i needed. Other solutions suggest pushing pruned local branches to the remote to remove them there as well, but that doesn't help when the remote has been removed or no longer exists. This approach removed the local references to the remote branches i no longer have access to. Commented Sep 16, 2019 at 22:14