How to tell which branch a github commit was for?

If you know the commit number, you can simply do this

git branch --contains <commit>

This should give you the branch name in which the commit was made.

UPDATE: On GitHub specifically, you now can see the branch a given commit is part of. The blog post "Branch and Tag Labels For Commit Pages" details:

If the commit is not on the default branch, the indicator will show the branches which contain the commit. If the commit is part of an unmerged pull request, a link will be shown.

enter image description here


If it's a fairly recent commit, you can go to your network graph (e.g., https://github.com/BenHocking/ShortCircuitGA/network) and hover over each node on a branch until you find the commit you're looking for. It's not efficient, but it's the only way I know how to do it directly from GitHub. (If you've got SourceTree, GitX, or other visual Git clients, there might be other alternatives, as well as command line alternatives.)


From git help branch:

With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit).

With --merged, only branches merged into the named commit (i.e. the branches whose tip commits are reachable from the named commit) will be listed.

With --no-merged only branches not merged into the named commit will be listed. If the argument is missing it defaults to HEAD (i.e. the tip of the current branch).


OK, the answer to this question, fundamentally, is: there is no definitive way to tell. Mercurial actually tags commits with the name of the branch they were checked in to, but git simply doesn't; apparently, it isn't considered important what the name of the branch was. This was a design decision and it doesn't look like it's going to change.

Tags:

Git

Github