Git Fetch Doesn’t Fetch All Branches
Today, I am going to share a very common git-related problem that you can fix easily.
Symptoms :
- When you trigger a
git fetch
, it only fetches changes in the master branch. - Even though you have pushed changes to your remote repository regarding other branches, the
git fetch
command doesn’t update them locally. You’ll see likegit fetch
does nothing. - Can receive errors when attempting to checkout
error: pathspec ‘the_new_branch_name’ did not match any file(s) known to git.
Reason:
This can be happened due to the limitations that are applied by git configs. As implied by its name Git configs are configuration values on a global or local project level for Git.
If we don’t use any options, git configs
are written into the local level. Local-level configs are stored in .git/config
folder inside the repository.
STEP 1 : Use the following command to check the current settings on fetch
Check whether your output in following manner:
This configuration will limit you to fetch only from the mentioned branch.
Solution:
STEP 2 : You can simply edit the configuration to allow to fetch from any branch
This will allow you to sync every remote branch update with your local. Now you can try git fetch
and it must work!!
BONUS : Fetch vs Pull
You can use git fetch
when you need to sync your local repository with the remote but still you don’t merge the changes into your working directory. It doesn’t transfer any files, but it lists what are the changes that happened in the remote.
git pull
drag the file changes down and merge them with what you are currently working on.