0

I am confused about

git fetch origin master vs git fetch origin master:master.

I know first will fetch from repository and specified branch.

what about second git fetch origin master:master?

1 Answer 1

4

The argument you're varying in these examples is called the refspec.

In the first example, you're using a shorthand that specifies the source ref to fetch (master) but does not specify a target ref to update. Default behavior would apply, which with a typical setup means origin/master would be updated.

The second example, you provide a source (master), then a : to separate that from a destination, then a destination (also master). This will attempt to directly update the local master branch of your local repo - rather than the origin/master remote branch ref. It may fail (e.g. if the local repo is a non-bare repo in a default configuration, and it has master checked out).

If you want to use explicit refspec but you still want to update the remote ref, you could say

git fetch origin master:origin/master
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.