1

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

1 Answer 1

4

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")

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.