Sithu
Sithu

Reputation: 4862

how to get all branches of my forked git repo

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:

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.

Upvotes: 3

Views: 7477

Answers (2)

Sithu
Sithu

Reputation: 4862

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://[email protected]':
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

Upvotes: 7

Kache
Kache

Reputation: 16747

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?

Upvotes: 1

Related Questions