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.
From /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:
is the same, when git remote is configured by default, than
It will tell Git what to fetch and where to store the resulting commit.
But:
means you don’t benefit from the default refspec setting
origin +refs/heads/*:refs/remotes/origin/*, which means you are doing:(you fetch the remote
HEADwithout specifying where to put it).The resulting commit is stored in
FETCH_HEADref.See “Having a hard time understanding
git-fetch” for more.(and “
git fetchwith path instead of remote“)