Git & GitHub Interview Question #26

How do you list branches in Git?

Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Junior Beginner

Quick Interview Answer

git branch lists local branches, with the currently checked-out branch marked. Options can also show remote-tracking branches or both local and remote-tracking branches.

Detailed Explanation

git branch lists local branches, with the currently checked-out branch marked. Options can also show remote-tracking branches or both local and remote-tracking branches.

Listing branches is useful before switching, merging, deleting, or checking whether a branch already exists.

Code Example

git branch

# Remote-tracking branches
git branch -r

# Local and remote-tracking branches
git branch -a