1

We have a team of 50+ developers and people do not delete their feature branches after merging them on the main-stream branch.

We have four main-stream branches develop, staging, demo, and master. We follow to create a separate branch for each JIRA ticket and that branch should be deleted once it merged on the origin branch.

So I want to get the list of all merged branches along with the creator to prepare the stats but could not find a proper way to do this. Find multiple answers on StackOverflow but could not find any suitable.

SHIVAM JINDAL
  • 2,844
  • 1
  • 17
  • 34
  • Does this answer your question? [How can I know if a branch has been already merged into master?](https://stackoverflow.com/questions/226976/how-can-i-know-if-a-branch-has-been-already-merged-into-master) – Rajat Mishra Dec 18 '20 at 20:46
  • @RajatMishra No, It does not show branch creator. – SHIVAM JINDAL Dec 18 '20 at 20:47
  • GitHub does not provide a way to query who created a branch. You can see who created the commits on the branch, but if I pushed commits created by someone else, you could not tell I was the pusher. – bk2204 Dec 19 '20 at 04:13
  • Git itself does not store any information about who created a branch name (because that's pointless; branch names are not important). GitHub could store this information somewhere outside Git, but doesn't (because that's pointless). – torek Dec 19 '20 at 13:03

1 Answers1

1

Use git for-each-ref with --merged=HEAD to filter on merged branch then use a format to get the committer by getting the last person to commit to that branch.

git for-each-ref --merged=HEAD --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate

You can add a grep on refs/remotes/origin/ to get only remote branches

git for-each-ref --merged=HEAD --format='%(committerdate) %09 %(authorname) %09 %(refname)' --sort=committerdate | grep 'refs/remotes/origin/'

From Find out a Git branch creator and How can I know if a branch has been already merged into master?

Johan Kaving
  • 4,870
  • 1
  • 27
  • 21
Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • `--no-merged=HEAD` It will give non-merged branch, but I need merged branches. Also I need to check whether branch is merged on the point it created instead of checking whether branch is merged on master. – SHIVAM JINDAL Dec 19 '20 at 13:42
  • I have updated for `merged` I don't understand what you call the `point it created.` You can run this on command on the different main-stream branch, but if you merge `develop` in `master` you will have duplicated. as the branch will be in the history of several main-stream branch – Ôrel Dec 19 '20 at 19:52
  • I ran the above-provided command and it printed lots of branches but when I searched some of these branches on the GitHub repo, they don't exist. – SHIVAM JINDAL Dec 20 '20 at 19:50
  • You should clean your local clone if you have object in local that are not on the server. – Ôrel Dec 20 '20 at 20:30
  • You can check remote branch with `git branch -r` – Ôrel Dec 20 '20 at 20:36