开发者

git fetch origin creates a new branch

I sync my development code on 2 machines using a git bare repository on a usb drive (followed these steps git setup for backup & sync between 2 computers).

I push my changes to the bare repo on the USB and then fetch & merge on the other machine.

My understanding was that these 2 commands are same, but their output is different. The log shows that the first command creates a new branch.

Method 1
git fetch origin
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Fro开发者_开发百科m /usb/backup/code
 * [new branch]      master     -> origin/master


Method 2
git fetch /usb/backup/code.git
From /usb/backup/code
 * branch            HEAD       -> FETCH_HEAD


That is because:

git fetch origin 

is the same, when git remote is configured by default, than

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

It will tell Git what to fetch and where to store the resulting commit.

But:

git fetch path/to/.git

means you don't benefit from the default refspec setting origin +refs/heads/*:refs/remotes/origin/*, which means you are doing:

git fetch path/to/.git HEAD:

(you fetch the remote HEAD without specifying where to put it).
The resulting commit is stored in FETCH_HEAD ref.

See "Having a hard time understanding git-fetch" for more.
(and "git fetch with path instead of remote")

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜