2

How can I delete all git branches which have been merged? show how to delete branches that have been merged. However, in GitHub, there is now a "Squash and merge" and a "Rebase and merge" option, both of which is not detected by git branch --merged.

Is there a way to identify all the branches that essentially generates an empty commit if merged into master?

EDIT: looking for a programmatic way via the CLI, similar to the linked question.

Community
  • 1
  • 1
neverendingqs
  • 4,006
  • 3
  • 29
  • 57
  • Just `git diff` the branch tips: `git diff xyz master` is empty if the source tree at the tip of `xyz` matches the source tree at the tip of `master`. (This is true whether both names translate to the same commit hash, or not, as long as the *tree* with the commits matches.) – torek Feb 17 '17 at 18:13
  • git itself does not provide such way. Maybe you could get from Github – max630 Feb 19 '17 at 16:30

2 Answers2

0

One thing you can compare other branches with master. If no difference found then delete the branch.

$ git checkout master

$ git branch           
$ git diff HEAD..branch1      # see what is in 'branch1' that is not in 'master' branch

# if no difference found then delete the branch
$ git branch -D branch1    
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
0

The easiest way may be through the GitHub web UI. Navigate to your repository. Click on the number of branches:

enter image description here

GitHub groups branches in the repos by Active, Stale, Yours, and Default. You will find color coded buttons that mark them as Open, Closed, or Merged. To the right of the button is a trashcan button you can use to delete the branch.

enter image description here

CJ Johnson
  • 1,081
  • 9
  • 13