3

I have cloned, pulled and fetched my remote git repo at BitBucket. But I could only get the master branch. My repo at BitBucket has 4 branches:

  • master
  • fix/cleanup
  • etc/schema_note
  • feature/sampledata

enter image description here

I have found the two questions this and that. I followed some of the instructions in those questions.
When I tried git branch -a, I could not see the other three branches.

*master  
 remotes/origin/HEAD -> origin/master  
 remotes/origin/master

I tried git checkout origin/fix/cleanup. I got an error message.

error: pathspec 'origin/fix/cleanup` did not match any file(s) known to git.

I tried checkout -b, but got another error.

$ git checkout -b fix/cleanup origin/fix/cleanup
fatal: Cannot update paths and switch to branch 'fix/cleanup' at the same time.
Did you intend to checkout 'origin/fix/cleanup' which can not be resolved as com
mit?

I also tried to execute the oneliner.

for remote in `git branch -r`; do git branch --track $remote; done

But it gave me the new branches origin/HEAD and origin/master in my local, not for the other 3 branches. What is going on my repo?

I tried git fetch --all and git pull --all. They gave me nothing changed.

Community
  • 1
  • 1
Sithu
  • 4,752
  • 9
  • 64
  • 110
  • If you cloned the repo, you already have all (remote) branches. – Kache Sep 08 '14 at 18:28
  • See also http://stackoverflow.com/a/25663746/6309 – VonC Sep 08 '14 at 18:30
  • @VonC I don't think that's the answer, here. The remote branches in question are not even listed in the output of `git branch -a`... – jub0bs Sep 08 '14 at 18:32
  • @Jubobs true... some `git fetch` should update that. – VonC Sep 08 '14 at 18:34
  • @VonC But the OP writes: *I have cloned, pulled and fetched my remote git repo*. It doesn't add up... – jub0bs Sep 08 '14 at 18:35
  • @Sithu Is your repository public, by any chance? – jub0bs Sep 08 '14 at 18:36
  • @Jubobs that can happen if you clone a cloned repo. First clone has all the remote branches, but the clone of the clone would have only master. – VonC Sep 08 '14 at 18:36
  • @VonC Really? How? I thought clones were all equal... Well, aside from unreachable objects that don't get transmitted. – jub0bs Sep 08 '14 at 18:38
  • @Jubobs a clone, yes. But a clone of a clone, no. – VonC Sep 08 '14 at 18:38
  • @VonC I'm intrigued. Can you think of a relevant link that would tell me more? – jub0bs Sep 08 '14 at 18:39
  • 1
    @Jubobs not really, but it is easy to test: clone a repo which has a lot of branches, then clone that clone: the `refs/remotes` namespace isn't clone. Only `refs/heads` – VonC Sep 08 '14 at 18:40
  • could [git namespaces](http://git-scm.com/docs/gitnamespaces.html) be relevant here? – Kache Sep 08 '14 at 18:45
  • @jubobs my repo is private and fork. – Sithu Sep 09 '14 at 01:07
  • Orignally, I cloned it using `--depth 1`. Please check http://goo.gl/o0LQeq – Sithu Sep 09 '14 at 04:12
  • Possible duplicate of [How to fetch all remote branches?](http://stackoverflow.com/questions/39957760/how-to-fetch-all-remote-branches) – kenorb Oct 11 '16 at 20:33

2 Answers2

7

I eventually found a fix. I tweaked the git config file. I changed

fetch = +refs/heads/master:refs/remotes/origin/master

to

fetch = +refs/heads/*:refs/remotes/origin/*

Then, $ git fetch --all worked for the changes.

Fetching origin
Password for 'https://myusername@bitbucket.org':
remote: Counting objects: 993, done.
remote: Compressing objects: 100% (581/581), done.
Receiving objects: 100% (966/966), 723.76 KiB | 8.00 KiB/s, done.
emote: Total 966 (delta 324), reused 964 (delta 322)Resolving deltas:   0% (0/32

Resolving deltas: 100% (324/324), completed with 21 local objects.
From https://bitbucket.org/myusername/myproj
 * [new branch]      etc/schema_note -> origin/etc/schema_note
 * [new branch]      feature/sampledata -> origin/feature/sampledata
 * [new branch]      fix/cleanup -> origin/fix/cleanup

Now, $ git branch -a started to list all remote branches;

* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/etc/schema_note
  remotes/origin/feature/sampledata
  remotes/origin/fix/cleanup
  remotes/origin/master

Finally, I checkout for every branch.

TPP@SITHU /d/xampp/htdocs/myproj (master)
$ git checkout etc/schema_note
Branch etc/schema_note set up to track remote branch etc/schema_note from origin.
Switched to a new branch 'etc/schema_note'

TPP@SITHU /d/xampp/htdocs/myproj (etc/schema_note)
$ git checkout feature/sampledata
Branch feature/sampledata set up to track remote branch feature/sampledata from
origin.
Switched to a new branch 'feature/sampledata'

TPP@SITHU /d/xampp/htdocs/myproj (feature/sampledata)
$ git checkout fix/cleanup
Branch fix/cleanup set up to track remote branch fix/cleanup from origin.
Switched to a new branch 'fix/cleanup'

Here is my final repo branch list:

$ git branch -a
  etc/schema_note
  feature/sampledata
* fix/cleanup
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/etc/schema_note
  remotes/origin/feature/sampledata
  remotes/origin/fix/cleanup
  remotes/origin/master
Sithu
  • 4,752
  • 9
  • 64
  • 110
1

If you cloned the repo, you should already have all remote branches.

The way git works is every copy of the repository is basically the same. The moment you clone a repo, you get everything the remote server has, including all history.

If you see branches in one place but not another, (e.g. on one client but not another), then it can only mean:

  1. There are branches local to one location that hasn't been propagated to the remote server

    and/or

  2. The local client hasn't fetched/pulled the propagated changes

edit

actually, could git namespaces be relevant here?

Community
  • 1
  • 1
Kache
  • 15,647
  • 12
  • 51
  • 79