Bain Markev
Bain Markev

Reputation: 2995

How to update remote branch information?

In a git repository, a remote branch I am not tracking was deleted. When I type

git branch -r

the deleted branch still shows up (and I can check it out)

What git command do I have to run to update this info?

Upvotes: 132

Views: 94758

Answers (6)

Flo
Flo

Reputation: 2778

git remote update --prune

Should refresh all remotes' branches, adding new ones and deleting removed ones.

Edit: The remote update command basically fetches the list of branches on the remote. The --prune option will get rid of your local remote tracking branches that point to branches that no longer exist on the remote.

Upvotes: 195

Aidan Donohoe
Aidan Donohoe

Reputation: 301

Also useful for seeing new remote branches:

git fetch --all

Upvotes: 15

MarceloCouto
MarceloCouto

Reputation: 31

Try this command

git gc --prune=now

Upvotes: 3

Jakub Narębski
Jakub Narębski

Reputation: 323454

If it were branches in remote repository that got deleted, and you want to update all local remote-tracking branches at once, you can use

$ git remote prune <remotename>

to delete all stale remote-tracking branches for a given remote (i.e. those that follow branches which were removed in remote repository).

See git remote documentation.

Upvotes: 294

Garrett Hyde
Garrett Hyde

Reputation: 5597

If you perform something like

git branch -d -r remote_name/branch_name

you only remove your local checkout. This command doesn't do anything to the remote repository, which is why it still shows up.

Solution:

git push origin :branch_name

will remove the the remote branch (note the ':'), and

git branch -d branch_name

will remove your local checkout.

(Reference)

Upvotes: 42

mikerobi
mikerobi

Reputation: 20878

You can combine the -r and -d flags to delete remote branches.

Upvotes: 2

Related Questions