Search code examples
gitgithubcaffegit-forkremote-branch

How to add fork as branch?


There are a lot of forks of Caffe, for example MS have their own Caffe fork.

What I want to do is to compare some fork to master branch of original Caffe.

I know that using git I can compare 2 branches, but my question is how to add fork as branch.

I tried this:

git clone https://github.com/BVLC/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 32907, done.
remote: Total 32907 (delta 0), reused 0 (delta 0), pack-reused 32907
Receiving objects: 100% (32907/32907), 43.55 MiB | 571 KiB/s, done.
Resolving deltas: 100% (21962/21962), done.

cd caffe_BVLC/

git branch -l
* master

git remote add caffe_MS https://github.com/Microsoft/caffe.git

git remote -v
caffe_MS    https://github.com/Microsoft/caffe.git (fetch)
caffe_MS    https://github.com/Microsoft/caffe.git (push)
origin  https://github.com/BVLC/caffe.git (fetch)
origin  https://github.com/BVLC/caffe.git (push)

git fetch caffe_MS
remote: Counting objects: 409, done.
remote: Total 409 (delta 177), reused 177 (delta 177), pack-reused 232
Receiving objects: 100% (409/409), 136.98 KiB, done.
Resolving deltas: 100% (279/279), completed with 89 local objects.
From https://github.com/Microsoft/caffe
 * [new branch]      bvlc_merge_2016_03_04 -> caffe_MS/bvlc_merge_2016_03_04
 * [new branch]      bvlc_windows_matlab -> caffe_MS/bvlc_windows_matlab
 * [new branch]      master     -> caffe_MS/master
From https://github.com/Microsoft/caffe
 * [new tag]         0.1w       -> 0.1w

git branch -l
* master

git checkout --track caffe_MS/MS
fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'caffe_MS/MS' which can not be resolved as commit?

What I'm doing wrong, whick branch name I should specify?

Update: Result of solution by @hek2mgl

git clone https://github.com/BVLC/caffe.git
Cloning into 'caffe'...
remote: Counting objects: 33290, done.
remote: Total 33290 (delta 0), reused 0 (delta 0), pack-reused 33290
Receiving objects: 100% (33290/33290), 43.93 MiB | 484 KiB/s, done.
Resolving deltas: 100% (22252/22252), done.
cd caffe
git remote add caffe_MS https://github.com/Microsoft/caffe.git
git fetch caffe_MS master
remote: Counting objects: 379, done.
remote: Total 379 (delta 111), reused 111 (delta 111), pack-reused 268
Receiving objects: 100% (379/379), 130.06 KiB, done.
Resolving deltas: 100% (246/246), completed with 62 local objects.
From https://github.com/Microsoft/caffe
 * branch            master     -> FETCH_HEAD
git diff caffe_MS/master
fatal: ambiguous argument 'caffe_MS/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

Solution

  • I know that using git I can compare 2 branches, but my question is how to add fork as branch.

    When you say you know how to compare two branches, I think you really meant you know how to compare local branches, and what you're missing is how to compare remote branches.

    First of all, you can see a list of remote branches with:

    git branch -r
    

    And you can compare remote branches by prefixing with the remote names, for example:

    git diff origin/master caffe_MS/master
    

    As for the last error, it's unclear what you're trying to do with git checkout --track caffe_MS/MS. Your explanation is about comparing branches and adding branches, you never mention tracking. If you want to checkout a branch from a fork, you can use the same syntax as when checkout a branch of origin:

    git checkout -b caffe_MS_master caffe_MS/master