How do I update the remote branches list in Git from the server?

20,562

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.

Share:
20,562

Related videos on Youtube

Kate Zz
Author by

Kate Zz

Updated on July 28, 2021

Comments

  • Kate Zz
    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
      Wolf over 8 years
      just do a git fetch
    • Remi Guan
      Remi Guan over 8 years
      try git branch -a command. If you can't see other branches...did you really push other branches to the server?
    • Mohsin Bukhari
      Mohsin Bukhari almost 4 years
      @Wolf after using this command. It still shows deleted remote branches
    • Wolf
      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
    Mohsin Bukhari almost 4 years
    after using these commands. It still shows deleted remote branches
  • Mohsin Bukhari
    Mohsin Bukhari almost 4 years
    after using this command. It still shows deleted remote branches
  • Sébastien Dawans
    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
    Guilherme Abacherli over 3 years
    try git fetch --all --prune, will probably clear branches that no longer exist in the remote repository