How do I update the remote branches list in Git from the server?
Solution 1
You can use the following commands to update the list of local branches from remote:
git fetch --prune
git pull --prune
Also you can set to update the local list of remote git branches automatically every time you run git pull
or git fetch
using below command.
git config remote.origin.prune true
Solution 2
In the second local repository:
git fetch # Retrieves updates from remote repo
git branch -a # View all local and remote branches
Solution 3
Execute the command:
git fetch --all
So the local repository will download all the new branches/tags that is in the server.
If you want to remove from the local the ones that have been removed from the remote server, try this:
git fetch --all --prune
As seen in the git doc about the fetch command.
Related videos on Youtube
Kate Zz
Updated on July 28, 2021Comments
-
Kate Zz almost 3 years
How can I update the remote branches list in Git?
I have pushed a branch to Git on the server. On the second local copy of the repository, I want to get that branch and do:
show branch -r
But I don't have the new branch in this list.
How can I update Git's remote branch list?
-
Wolf over 8 yearsjust do a
git fetch
-
Remi Guan over 8 yearstry
git branch -a
command. If you can't see other branches...did you really push other branches to the server? -
Mohsin Bukhari almost 4 years@Wolf after using this command. It still shows deleted remote branches
-
Wolf almost 4 years
git fetch --prune
will get rid of deleted remote branches and fill in new remote branches at the same time
-
-
Mohsin Bukhari almost 4 yearsafter using these commands. It still shows deleted remote branches
-
Mohsin Bukhari almost 4 yearsafter using this command. It still shows deleted remote branches
-
Sébastien Dawans over 3 years@MohsinBukhari you can use
git fetch -p
to delete (prune) remote-tracking branches which no longer exist on the remote -
Guilherme Abacherli over 3 yearstry
git fetch --all --prune
, will probably clear branches that no longer exist in the remote repository