jww
jww

Reputation: 102464

How to restore remote branches from GitHub that Git seems to have lost locally?

I had two local branches go missing on me after rebasing all local branches against Master. I then performed a subsequent push naively thinking all branches were sync'd against master and they would be available for everyone to use.

I deleted the local clone and performed a new clone. Now all the branches are gone locally even though they are available in GitHub.

How do I force this stupid tool to give me all the branches?


Here's the repo with the four branches. Here's what Git is giving me after a fresh clone:

$ git branch
* master

Notice windows-store, arm-neon and atomics are now missing locally.


These seem related: Git repository lost its remote branches? and Mysterious vanishing branches in git. But since deleting the local directory and then performing the fresh clone, it seems like Git should be able find all the branches.

Upvotes: 0

Views: 236

Answers (2)

Vampire
Vampire

Reputation: 38734

Of course they are "missing". If you do git branch -r you will get the branches of remotes, or if you do git branch -a you will get all, local and remote branches. On clone Git (which is a very intelligent tool) looks what the HEAD reference of the remote repository is and creates a local version of it in your local clone. If you want local branches for your other remote branches, just create them or just check them out by name and the according local branch will be created automatically.

Update: If you are using --mirror on the clone command you will have the branches as local branches instead of remote branches, but this is usually not what you want for working locally with the repository.

Upvotes: 4

VijayGupta
VijayGupta

Reputation: 685

Update the remote-tracking branches:

git fetch origin

The above command copies all branches from the remote refs/heads/ namespace and stores them to the local refs/remotes/origin/ namespace, unless the branch..fetch option is used to specify a non-default refspec.

than after you can use git command

git branch -r

it will show all branches

Upvotes: 1

Related Questions