Because branches are really just pointers to particular commits in the repo, git doesn't really keep track of branches like that.
That being said, it would be possible to find the commit that caused the problem and very likely the branch that was pushed (though this will depend on your workflow).
First use git log -1 -- <file>
, this will show the last commit involving the file. From your question, there should really be only one.
Knowing this all we need to do is find the branches that contain this particular commit. From this answer the command we want is git branch -a --contains <commit>
This list should contain the remote master and the culprit branch that you are looking for. The -a
will add all the remote branches that your repo is aware of.
Depending on how much merging happened, this list should be limited to master and the branch that you are looking for. Otherwise it will contain all the branches that were also merged with the branch that you are looking for.
If that is the case, you can examine the history to find the merge commit. git log --graph
will 'show' the branches and merges that occur. Enter this command and then type / <sha of file commit>
which should take you to the commit that created the file. Then trace the line for the commit forward until you get the merge commit which should contain the name of the branch. This method can be messy depending on what you history looks like.