Git: updating remote branch information

Git

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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.

Solution 3 - Git

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)

Solution 4 - Git

Also useful for seeing new remote branches:

git fetch --all

Solution 5 - Git

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

Solution 6 - Git

Try this command

git gc --prune=now

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBain MarkevView Question on Stackoverflow
Solution 1 - GitJakub NarębskiView Answer on Stackoverflow
Solution 2 - GitFloView Answer on Stackoverflow
Solution 3 - GitGarrett HydeView Answer on Stackoverflow
Solution 4 - GitAidan DonohoeView Answer on Stackoverflow
Solution 5 - GitmikerobiView Answer on Stackoverflow
Solution 6 - GitMarceloCoutoView Answer on Stackoverflow