Thanks for the lead! git fetch -all fetches all branches of all remotes. git fetch origin fetches all branches of the remote origin .
1 Answer. git fetch --all and git pull -all will only track the remote branches and track local branches that track remote branches respectively. Run this command only if there are remote branches on the server which are untracked by your local branches. Thus, you can fetch all git branches.
This can happen if your repo has 0 commits. If you make a commit, your current branch will appear when you do: git branch . Show activity on this post. Show activity on this post.
To get all the changes from all the branches, use git fetch --all . And if you'd like to clean up some of the branches that no longer exist in the remote repository, git fetch --all --prune will do the cleaning up!
The problem can be seen when checking the remote.origin.fetch
setting
(The lines starting with $
are bash prompts with the commands I typed. The other lines are the resulting output)
$ git config --get remote.origin.fetch
+refs/heads/master:refs/remotes/origin/master
As you can see, in my case, the remote was set to fetch the master branch specifically and only. I fixed it as per below, including the second command to check the results.
$ git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
$ git config --get remote.origin.fetch
+refs/heads/*:refs/remotes/origin/*
The wildcard *
of course means everything under that path.
Unfortunately I saw this comment after I had already dug through and found the answer by trial and error.
I had this issue today on a repo.
It wasn't the +refs/heads/*:refs/remotes/origin/*
issue as per top solution.
Symptom was simply that git fetch origin
or git fetch
just didn't appear to do anything, although there were remote branches to fetch.
After trying lots of things, I removed the origin remote, and recreated it. That seems to have fixed it. Don't know why.
remove with:
git remote rm origin
and recreate with:
git remote add origin <git uri>
You need to run
git remote update
or
git remote update <remote>
Then you can run git branch -r
to list the remote branches.
To track a (new) remote branch as a local branch:
git checkout -b <local branch> <remote>/<remote branch>
or (sometimes it doesn't work without the extra remotes/
):
git checkout -b <local branch> remotes/<remote>/<remote branch>
Had the same problem today setting up my repo from scratch. I tried everything, nothing worked except removing the origin and re-adding it back again.
git remote rm origin
git remote add origin [email protected]:web3coach/the-blockchain-bar-newsletter-edition.git
git fetch --all
// Ta daaa all branches fetched
write it from the terminal
git fetch --prune.
it works fine.
To make it more specific Create a tracking branch, which means you are now tracking a remote branch.
git branch --track branch remote-branch
git branch --track exp remotes/origin/experimental
After which you can
git branch # to see the remote tracking branch "exp" created .
Then to work on that branch do
git checkout branchname
git checkout exp
After you have made changes to the branch. You can git fetch and git merge with your remote tracking branch to merge your changes and push to the remote branch as below.
git fetch origin
git merge origin/experimental
git push origin/experimental
Hope it helps and gives you an idea, how this works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With