I have a git repository for a project at work. Each time we release a version of our software, we create a release branch for it. There's a release1.0 branch, a release 1.1 branch, etc. When we need to create a hotfix for that release, we commit the fix to that release branch, and then we merge that fix into our master development branch.
Sometimes we forget that last step in our rush to fix a production bug, and then a new release goes out without the hotfix for our previous problem.
Is there an easy git command that checks to see if all our our release branches have been merged into master, and if not, which commits in which branches?
You can use the git merge-base command to find the latest common commit between the two branches. If that commit is the same as your branch head, then the branch has been completely merged.
With git branch --merged <commit> , your local list of branches will be filtered by all the branches who have been merged into a given branch or commit. Similar to above, you could type git branch --no-merged <commit> and only the branches not merged into the named commit would be listed.
Once you've completed work on your branch, it is time to merge it into the main branch. Merging takes your branch changes and implements them into the main branch. Depending on the commit history, Git performs merges two ways: fast-forward and three-way merge.
Each branch compartmentalizes the commits related to a particular feature. Once the new feature is complete – i.e. a set of changes has been committed on the feature branch – it is ready to be merged back into the master branch (or other main code line branch depending on the workflow in use).
You could try git branch --no-merged master
. This should list all branches that haven't been merged into master
.
Another approach is to type git log master..branch
, which will show empty results if branch is merged into master, and will otherwise present a list of unmerged commits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With