0

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.

Community
  • 1
  • 1
jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    This would make a nice question without the insults. – choroba May 06 '16 at 14:21
  • Git might make a good tool if it wasn't so broken.... – jww May 06 '16 at 14:23
  • You should just be able to use `git checkout ` – cyroxis May 06 '16 at 15:00
  • 1
    @jww your lack of understanding does not make it a bad tool. – cyroxis May 06 '16 at 15:00
  • @cyroxis - You're right. The inability to match mental model for workflows and poor engineering decisions make it a bad tool; not an inexperienced operator. I've never seen a tool make so many simple tasks difficult. Its classic over engineering. – jww May 07 '16 at 03:17

2 Answers2

4

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.

Vampire
  • 35,631
  • 4
  • 76
  • 102
  • That workflow makes absolutely no sense. Why would a clone only clone part of a repo? What command do I need to execute to clone all of the repo? – jww May 06 '16 at 14:20
  • 3
    You always clone all of the repo. Each clone of a Git repository is an own full repository with all history and all remote branches. (unless you tell git otherwise to just fetch one branch or just the last x commits of each branch). The remote branches **ARE** already in your local clone, just in the namespace of the remote where they exist. You can e. g. have 10 remotes in a Git repository, each having the same branches, and all are at most logically connected to your local branches. If you want some remote branch as local branch, just check it out. This makes perfect sense. – Vampire May 06 '16 at 14:23
  • Besides that, you can use `--mirror` on clone but usually this is not what you want. – Vampire May 06 '16 at 14:46
  • @jww The workflow does make sense, it shows you what branches you are using and by default filters branches that you have not touched (e.g. consider large project with many developers and many branches you never personally work on). Those branches are available to you if you want them. – cyroxis May 06 '16 at 15:04
1

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

VijayGupta
  • 637
  • 3
  • 11