How to git fetch all branches

Greg Foster
Greg Foster
Graphite software engineer

This guide provides detailed steps to effectively fetch all branches from a remote repository, troubleshoot common issues, and understand the intricacies of git fetch.

Git fetch is a command used to download commits, files, and refs from a remote repository into your local repo. Fetching is crucial for keeping your local repository up-to-date with the remote repository without merging the changes into your current branch.

To fetch all branches from the remote repository, use:

Terminal
git fetch --all

This command fetches all branches from all remotes. It is a safe way to update your local repository with changes from the remote without altering your current working state.

If git fetch --all does not seem to fetch all branches, ensure your Git configuration is set to track all branches. You can do this by modifying the fetch configuration for your remote:

Terminal
git config --global remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

This configuration change tells Git to fetch all branches from the remote called origin and map them to your local refs/remotes/origin/.

If you need to fetch all tags along with branches, use the following command:

Terminal
git fetch --all --tags

This command fetches all tags in addition to branches from the remote repository, ensuring you have all the repository's references.

After fetching, you might want to check the list of all branches, including remote-tracking branches, with:

Terminal
git branch -a

This will show you all local and remote branches available in your repository. If some branches are missing, it might be due to the configuration or issues with the remote repository.

  • Git fetch not working: Check your network connection and remote repository URL (git remote -v).
  • Git fetch does not fetch all branches: Ensure your remote fetch configuration is set to track all branches as shown in Step 2.
  • Git fetch does not update local branches: Remember, git fetch does not merge changes into your local branches. You need to use git merge or git pull to apply these changes.
  • Git fetch origin does nothing: Verify the remote name (origin) and its configuration. Sometimes, the remote name might differ, or the fetch configuration might be set incorrectly.

To fetch a specific branch from the remote, you can use:

Terminal
git fetch origin <branch-name>

For multiple specific branches, you can fetch each one individually, or script the fetch commands if working with many branches.

If your repository has multiple remotes configured, you may want to fetch from all these sources:

Terminal
git fetch --all

This command covers all remotes, but you can also fetch from a specific remote by specifying its name:

Terminal
git fetch <remote-name>

For further reading on git fetch, see the official Git documentation.

Give your PR workflow
an upgrade today

Stack easier | Ship smaller | Review quicker

Or install our CLI.
Product Screenshot 1
Product Screenshot 2