Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know if a branch has been already merged into master?

Tags:

git

I have a git repository with multiple branches.

How can I know which branches are already merged into the master branch?

like image 643
hectorsq Avatar asked Oct 22 '08 18:10

hectorsq


People also ask

How can you tell if two branches are merged?

Find the merge base, and then check if git diff --name-only $merge_base branchA and git diff --name-only $merge_base branchB have anything in common. Otherwise, you'll need a work tree to try the merge in. You could easily create a second one - either clone the repository, or to save space, just create a work tree.

Does a branch still exist after merging?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.

What happens to branch after merge to master?

The answer is: nothing happens to the feature branch as a result of the merge. The new merge commit is added on the current branch (which is master when the merge is done).

Can we commit on branch that's already been merged with Master?

You can continue working on your branch and then when you merge with master again, it will bring the commits that are missing on master.


2 Answers

git branch --merged master lists branches merged into master

git branch --merged lists branches merged into HEAD (i.e. tip of current branch)

git branch --no-merged lists branches that have not been merged

By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.

like image 72
hectorsq Avatar answered Sep 19 '22 05:09

hectorsq


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.

Note that git branch -d does this sort of thing already because it will refuse to delete a branch that hasn't already been completely merged.

like image 20
Greg Hewgill Avatar answered Sep 20 '22 05:09

Greg Hewgill