0

This is a followup to:

How do I fetch only one branch of a remote git repository?

Which references:

https://www.kernel.org/pub/software/scm/git/docs/git-fetch.html

And which relies on understanding the refspec pattern of usage of git fetch:

git fetch [<options>] [<repository> [<refspec>…]]

To understand that usage pattern, an understanding of "refspec" is needed. For example:

Git - What is "Refspec"

The question which was asked was how to fetch a single branch (of a remote repository), with one popular answers:

git fetch <remote_name> <branch_name>

This answer is also popular:

git remote add -t <remote-branch-name> <remote-name> <remote-url>

My question is: How does one figure out how to reach that first form from the git fetch and refspec documentation?

I'm asking because "git fetch" is a very basic git operation, one of the starting commands for git beginners, and I'm finding myself at a loss to capture an adequate explanation of the command.

Thomas Bitonti
  • 1,179
  • 7
  • 14
  • See "CONFIGURED REMOTE-TRACKING BRANCHES" in https://www.kernel.org/pub/software/scm/git/docs/git-fetch.html. And `The format of a parameter is an optional plus +, followed by the source ref , followed by a colon :, followed by the destination ref . The colon can be omitted when is empty.` – ElpieKay Aug 23 '17 at 17:11

1 Answers1

0

If you're updating the current branch the command is

git pull origin master

where origin is the name of remote repo and master is the name of the branch to be fetched and merged into the current branch (it's supposed the current branch is your local master).

For any other branch the command is

git fetch origin branch:branch

This fetches commits from the remote branch branch, update local remote-tracking branch origin/branch and update local branch branch.

phd
  • 82,685
  • 13
  • 120
  • 165