1

After I clone from a bare git repository, my imported local repository doesn't have all the branches in it. Following is the architecture.

enter image description here

Here are the steps how this bare repository came into being.

  1. I had an existing repository (a in the figure). I did some branch filtering within this branch to rule out some useless directories.
  2. Created a new empty bare repository (b in the figure) using git init --bare new_repo.git
  3. In the a local repository, I changed the remote URL using git remote set-url origin /path/new_repo.git.
  4. Pushed the content of a to b using the command git push origin '*:*' and got success.
  5. At this stage running the command git branch -r shows all the remote branches correctly.git branch -r
  6. Now when I clone b (bare repository), the cloned local repository (c in the figure) gets created and it has the correct directory structure. But the problem is that when I try to list all the remote branches using git branch -r, it lists only the master branch.git branch -r

Why doesn't the cloned repository have all the remote branches and how can I have all those imported?

pomeh
  • 4,742
  • 4
  • 23
  • 44
Kashif Nazar
  • 20,775
  • 5
  • 29
  • 46
  • Do you mean `git push origin '*:*'`? If you really did `git push origin ':*:'` that might explain the problem (or perhaps repo `a` only has branch `master`, since `git push origin '*:*'` only pushes local branches, not remote-tracking branches). – torek Apr 09 '15 at 07:20
  • Thanks for the answer and correction. But I am baffled because after running `git push origin '*:*'` when I did `git branch -r`, it was showing all the remote repositories correctly, both on **a** and **b**. – Kashif Nazar Apr 09 '15 at 07:38
  • Hm, it's possible that `git push origin '*:*'` *does* push the remote-tracking branches. But if so, that's still useless, because `git clone` copies only the *local* branches in `b` from the bare repo `b` to new repo `c`. That's why you want these to be local branches on `b`. – torek Apr 09 '15 at 08:08
  • That was quite helpful @torek. Thanks a lot. How can I have those as local branches on b? – Kashif Nazar Apr 09 '15 at 08:16
  • There are a bunch of ways. The easiest at the start is to have them as local branches on `a`, so that pushing from `a` to `b` creates them as local branches on `b`. Given that they're already in place, though, one way is to log in to the server that hosts `b` and create local branches pointing to the same commit as the remote branches (then optionally delete the remote branches as they are probably not useful). Or, for each remote branch on `a`, push to a corresponding local branch on `b` (code for this won't fit as a comment). – torek Apr 09 '15 at 08:21

1 Answers1

3

git fetch origin or whatever your remote is set up to.

And then git checkout BRANCH_NAME

gran_profaci
  • 8,087
  • 15
  • 66
  • 99
  • Thanks for the answer but unluckily it doesn't help. $ git checkout AMS_ENH_021110 error: pathspec 'AMS_ENH_021110' did not match any file(s) known to git. – Kashif Nazar Apr 09 '15 at 07:31
  • ok... could you confirm that the remote branch you are looking for `AMS_ENH_021110` exists on the remote? Check it in the UI and make sure you are pointing to exactly the same remote url. – gran_profaci Apr 09 '15 at 07:47
  • When I run `git branch -r` on the bare repository, the branch is shown as a remote branch. But the command doesn't show this remote branch on the local repository. – Kashif Nazar Apr 09 '15 at 07:50