Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Determine if branch has been merged #110

Open
salcode opened this issue Jan 7, 2020 · 2 comments
Open

Determine if branch has been merged #110

salcode opened this issue Jan 7, 2020 · 2 comments

Comments

@salcode
Copy link
Member

salcode commented Jan 7, 2020

I'd like a way to determine if a branch has been merged into another branch. I'm not sure that this has a lot of stand-alone use however I think it would be helpful in the context of more complex scripts.

@salcode
Copy link
Member Author

salcode commented Jan 7, 2020

Manually

If you are doing this manually, using

git branch --merged

will give you a list of all branches that have been merged into your current branch.

Programmatically

While it is nice to be able to do this manually (and we could probably do some fancy grepping to get the answer), I think there is another approach.

git merge-base mybranch develop

Will give me the most recent common commit between mybranch and develop. If we compare this most recent commit on mybranch, if they are the same we'll know that develop is a superset of mybranch and thus mybranch has been merged into develop.

In other words, if

git merge-base mybranch develop

and

git rev-parse mybranch

return the same hash, then mybranch has been merged into develop

@salcode
Copy link
Member Author

salcode commented Jan 7, 2020

Alternatively, we could do

git log develop..mybranch

If there is no output then mybranch has no commits that do not appear in develop (i.e. it mybranch has been merged into develop), if there is any output then mybranch has commits NOT in develop (mybranch has no been merged into develop)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant