1

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
Community
  • 1
  • 1
mrgloom
  • 20,061
  • 36
  • 171
  • 301

2 Answers2

3

Update

You are using an ancient version of git. Update to git >= 2 to make the below commands work. I'm using 2.4.10.


The following commands will do the trick:

# Clone repo
git clone https://github.com/BVLC/caffe.git
cd caffe

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

# Fetch remote master from fork
git fetch caffe_MS master

# Compare to local master
# We are currently working in the local master that's why it can be omitted
git diff caffe_MS/master
hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • For some reason `git diff --name-only origin/master caffe_MS/master` works only if I use `git fetch caffe_MS` (not `git fetch caffe_MS master`, which gives error `fatal: ambiguous argument 'caffe_MS/master': unknown revision or path not in the working tree). ` – mrgloom Mar 09 '16 at 18:02
  • Can you try exactly my steps and just my steps? (Make a clean clone) It should work, I've tested it. – hek2mgl Mar 09 '16 at 18:08
  • I remove caffe folder(don't know what clean clone is) and tried these commands second time, see update, also `git --version` gives `git version 1.7.9.5`. – mrgloom Mar 10 '16 at 08:53
  • Your git is quite old, I'm using version 2.4.10. In version 2 git changed the way how branches are handled. – hek2mgl Mar 10 '16 at 08:57
1

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
janos
  • 120,954
  • 29
  • 226
  • 236