简体   繁体   中英

Why does git branch --merged not show all merged branches?

I created a feature branch, then created a PR for it. My PR was accepted and merged. The PR says, "the branch can be safely deleted." But when I do git branch --merged on the main branch, I don't see the merged branch. What I am doing wrong?

This is a difficult question to answer without knowing the exact workflow.

I assume since you 'created a PR' you forked/cloned a non-local repo to start with. Then you created a new branch in your local repository, made changes to add a feature, and committed those changes onto your local feature branch.

Beyond that it's a bit murkier. Here are a few steps you might take:

  1. You say you submitted a PR, but you don't say that you ever merged the feature branch with your local master branch. That suggests you may be following a workflow like this one . If that's the case, and you're running git branch --merged in your local repository, the reason you don't see your feature branch listed is that you never merged your feature branch into master in your local repository. This, IMO, is the most likely scenario. Try running git pull <name of your remote--probably origin> master from your local master branch, then trying running git branch --merged again.

  2. Fast-forwarding could cause some confusion, though it wouldn't create the issue you're describing on its own.

  3. You can always run git log on a given branch to see its full commit history. You could examine the commit history of your master and compare it to the commit history of origin/master to maybe find the discrepancy.

Hope this helps!

I have been struggling with this also. We are using gitlab's MR flow , which is probably the most simple merge based git flow.

What I have noticed is that we select to Squash Commits when a MR is merged. As a consequence this affects git history and prevents the --merged flag from working as expected.

I had similar problem, when feature branches were merged to develop and develop was merged to master. Such branches are not shown for

git branch --merged master, 
but shown for
git branch --merged develop

But it's better to use -r flag as recommended in How can I delete all Git branches which have been merged?

Remote git clear:

git branch -r --merged | grep -v '\*\|master\|develop\|release' | sed 's/origin\///' 
| xargs -n 1 git push --delete origin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM