Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why include `master` in the command `git fetch upstream master`?

In the section Pulling in upstream changes on help.github's Forking a project it states:

Some time has passed, the upstream repo has changed and you want to update your fork before you submit a new patch. There are two ways to do this:

$ git fetch upstream master

$ git merge upstream/master

Why are they including master in the fetch command? I've looked at the git help fetch information but I'm not understanding what including master does. Thanks.

like image 200
Matthew Rankin Avatar asked Jan 06 '10 16:01

Matthew Rankin


People also ask

What does git pull upstream master do?

The git pull command is used to fetch and download content from a remote repository and immediately update the local repository to match that content. Merging remote upstream changes into your local repository is a common task in Git-based collaboration work flows.

What is fetch upstream in git?

The git fetch command downloads commits, files, and refs from a remote repository into your local repo. Fetching is what you do when you want to see what everybody else has been working on.

What is the purpose of git fetch?

git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn't do any file transferring. It's more like just checking to see if there are any changes available). git pull on the other hand does that AND brings (copy) those changes from the remote repository.

How do I fetch upstream changes?

Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.


1 Answers

That allows you to:

  • update your local version of the master upstream branch only (as opposed as updating all branches of the upstream repo, which can be longer to do)
  • no trigger a merge right away (as opposed to the pull command)

The git merge will then try to merge that local version of the upstream master to your repo master branch.

So here, master is, for the fetch command, a refspec.

<refspec>

The format of a <refspec> parameter is an optional plus +, followed by the source ref <src>, followed by a colon :, followed by the destination ref <dst>.

The remote ref that matches <src> is fetched, and if <dst> is not empty string, the local ref that matches it is fast-forwarded using <src>.
If the optional plus + is used, the local ref is updated even if it does not result in a fast-forward update.

Here, <dst> is empty, so the matching local branch (your master) is updated.


Without master, that would give:

git fetch upstream 

The above command copies all branches from the remote refs/heads/ namespace and stores them to the local refs/remotes/upstream/ namespace, unless the branch.<name>.fetch option is used to specify a non-default refspec.

like image 134
VonC Avatar answered Nov 09 '22 23:11

VonC