Git & GitHub Interview Question #147

How can you find which branches contain a particular commit?

Security, Team Workflows, Troubleshooting & Senior Git/GitHub Scenarios Senior Advanced

Quick Interview Answer

git branch --contains can list local branches whose history contains a specified commit. Adding appropriate options can include remote-tracking branches.

Detailed Explanation

git branch --contains can list local branches whose history contains a specified commit. Adding appropriate options can include remote-tracking branches.

This is useful before deleting a branch or when investigating whether a fix has already reached main, a release branch, or another development line.

Code Example

git branch --contains <commit-id>

# Include local and remote-tracking branches
git branch -a --contains <commit-id>