Do I need to run a git fetch to see all remote branches with git branch -r ?
Or in other words: does a git branch -r execute a remote call, or only the known remote branches are displayed?
Do I need to run a git fetch to see all remote branches with git branch -r ?
Or in other words: does a git branch -r execute a remote call, or only the known remote branches are displayed?
Yes, but check the refspec used for your remote:
git config --get remote.origin.fetch
You should see:
+refs/heads/*:refs/remotes/origin/*
That would fetch all remote branches.
A refspec like +refs/heads/dev:refs/remotes/origin/dev
would only fetch and update the 'dev' remote tracking branch.
git branch
does not perform any network requests and will only show the currently known state of your local remote-tracking branches.
But it is also possible to view the branches of a remote repository with git ls-remote --heads
, which performs a network request without updating your local remote-tracking branches.
git branch -r
doesn't execute a remote call, it only lists the remote tracking branches you have locally. (see the folder ´.git/refs/remotes´)
Note that git branch -r
also will list a lot of remote branches which haven't existed for quite a long time unless you add the --prune
argument to you pull
and fetch
commands. (or you could change the settings to always prune when fetching.)