THE GITHTML FIELD GUIDE

List local and remote-tracking Git branches

Use git branch for local branches, git branch --remotes for remote-tracking references, and git branch -vv for local branches with upstream information. Remote-tracking names such as origin/main are locally stored observations of a remote. They do not become live server listings merely because their names contain the remote’s name.

Recognize the three names involved

A local branch such as feature/search is where your commits accumulate. The corresponding server branch is a reference in the remote repository. Your origin/feature/search reference records what your local Git last learned about that server branch. These can point to different commits until you exchange updates, so similar names do not imply synchronized content.

The asterisk in a normal branch listing marks the checked-out branch. Verbose output can include the latest commit and an upstream relationship. Ahead or behind counts rely on locally available information, not a fresh network request. Treat a branch listing as a repository map, then fetch if your decision requires current remote state.

Inspect before updating or deleting anything

These commands list branches without switching to them. The final fetch updates knowledge from origin, so first verify that origin is the intended repository and that network access is appropriate. A fetch is not a merge into your working branch. Inspect its output for authentication problems rather than treating an unchanged list as proof that no remote changes exist.

  1. If a remote-tracking branch appears but no local branch does, decide whether you need to create a local tracking branch or simply inspect the remote reference.
  2. If an upstream is marked gone, confirm the server branch was intentionally removed before changing tracking settings or deleting your local work.
shell
git branch
git branch --remotes
git branch -vv
git remote -v
git fetch origin

Use the map to explain synchronization

For a concrete example, your local feature branch may be two commits ahead of origin/feature because you committed offline. Another teammate may also have pushed to the server since your last fetch. Only after fetching can you accurately assess the relationship against the newly observed remote tip. Ahead does not mean safe to overwrite, and behind does not mean your local work is disposable.

Avoid branch cleanup as part of a listing task. A stale-looking name may preserve work that has not been merged, while a remote branch may have been renamed rather than abandoned. Record the exact local branch, upstream, and commit when handing the task to someone else. That small inventory makes later push or pull decisions much less ambiguous than saying that the branch is simply up to date.

Remote-tracking references are not separate editable copies of files. Checking out a branch determines the working snapshot; listing a reference only describes a name and its target.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All git fundamentals guides →

Read as MarkdownAll guides

List local and remote-tracking Git branches · gitHtml