Resolving git branch not showing all branches

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


When working with Git, it's common to encounter issues where not all branches seem to appear when you list them using the git branch command. This guide will walk you through the steps to ensure you can see all necessary branches in your local and remote repositories.

First, it's important to differentiate between local and remote branches in Git:

  • Local branches: These are branches that exist in your local repository, stored directly on your local machine.
  • Remote branches: These branches are references to the state of branches on your remote repositories (like GitHub or GitLab). To make changes to these branches you must commit and push to them from your local repository.
Join 20,000+ developers at top companies
Stop wrestling with Git commands
The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop googling Git commands.
main
diff1
diff2
  1. Not fetching the latest updates from remote: Git won't automatically show or update remote branches unless you explicitly fetch or pull the changes.
  2. Local branch not created: If a branch exists on the remote but not locally, it won’t appear when you list branches with git branch, which by default shows only local branches.
  3. Configuration issues: Misconfiguration in your Git settings can also lead to branches not being displayed.
  1. Fetch all remote branches

    Start by fetching all updates from your remote repository, which updates your remote-tracking branches:

    Terminal
    git fetch --all

    This command retrieves all branches from the remote, including those not yet tracked locally. Fetching frequently is key to keeping your local repository up to date with the most recent changes from the remote.

  2. List all branches including remote

    To see both local and remote branches, use:

    Terminal
    git branch -a

    This displays all branches available, including remote branches prefixed with remotes/.

  3. Check remote tracking branches

    If you're concerned that not all remote branches are showing up, you can check the remote tracking branches separately:

    Terminal
    git branch -r

    This command lists all branches that your local repository is tracking on the remote.

  4. Ensure correct remote is being used

    If branches are still missing, ensure you are connected to the correct remote repository:

    Terminal
    git remote -v

    This lists all remotes along with their URLs. Verify that the remote URLs match the repository from which you expect to see branches.

    If you discover that the wrong remote repository is configured, you can switch to the correct one by using the git remote set-url command, followed by the remote name and the new URL. For example, git remote set-url origin https://github.com/user/repository.git would change the URL of the remote named 'origin' to the provided GitHub repository URL, effectively updating your remote configuration.

  5. Create a local branch tracking a remote branch

    If a remote branch exists but you don’t have a local branch tracking it, you can set up a local branch to track the remote branch:

    Terminal
    git checkout -b [local-branch-name] [remote-name]/[remote-branch-name]

    For example, to check out a local branch called feature that tracks origin/feature:

    Terminal
    git checkout -b feature origin/feature
  6. Troubleshooting configuration issues

When working with Git, non-standard configurations can sometimes lead to issues with branch visibility or behavior. These problems often arise from local settings that deviate from typical configurations, affecting how branches and remotes are handled.

The command git config --list is used to display all the settings in your Git configuration that can affect your local repository's operations. This command compiles settings from various scopes (system, global, and local), providing a comprehensive view of how Git is configured on your machine.

  1. Execute the command: Running git config --list in your terminal will list all the Git configuration settings currently active. This output includes all custom configurations applied at different levels, such as user-specific settings (global) or repository-specific settings (local).

  2. Inspect relevant settings: Specifically, look for entries that start with branch. and remote.. These entries control the behavior of your branches and the settings for your remote repositories, respectively. For instance, branch.<branchname>.remote and branch.<branchname>.merge are important for understanding which remote branch is tracked by your local branches and how they merge.

When you run git config --list, you might see output like this:

Terminal
remote.origin.url=https://github.com/username/repo.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main
  • remote.origin.url: Shows the URL of the remote named 'origin'. This should match the repository URL you intend to interact with.
  • remote.origin.fetch: Indicates the fetch configuration for 'origin', typically set to fetch all branches (refs/heads/*) into your local remote-tracking branches (refs/remotes/origin/*).
  • branch.main.remote: Tells you that the local branch main is tracking changes from the remote named 'origin'.
  • branch.main.merge: Specifies that the local main branch merges with the remote main branch.

By reviewing these settings, you can identify and resolve configuration mismatches that might be causing branch visibility or tracking issues in your Git environment. This process ensures that your local repository aligns correctly with your remote repositories.

Join 20,000+ developers at top companies
The best engineers use Graphite to simplify Git
Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.
main
diff1
diff2

If, after following the above steps, you still are not seeing the branches you expect to, see the official Git documentation for further troubleshooting.

On this page
Git gud
"It's the first Git workflow I've used that actually feels good."
–@robboclancy
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2