0

If I run git fetch , how does git resolve the remote ?

From git fetch doc ,

When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch.

Does that mean it will consult branch.branchName.remote config value like git push ?

It is not very clear to me what does it mean ...unless there’s an upstream branch configured for the current branch .The doc does not explicitly says what if upstream is configured ?

For more details : Run git push, pull and fetch without refspec argument

Number945
  • 4,631
  • 8
  • 45
  • 83
  • Possible duplicate of [Run git push, pull and fetch without refspec argument](https://stackoverflow.com/questions/34523494/run-git-push-pull-and-fetch-without-refspec-argument) – phd Sep 18 '18 at 17:12
  • @phd , My apologies but I have read the answer but I am unable to find answer to my question there. How git fetch resolves the remote , I am unable to find/grasp it. Can u pls point it out that part or better give an answer here , that will be very helpful. – Number945 Sep 18 '18 at 23:10
  • 1
    This part, e.g.: *When the command line does not specify where to push with the argument, branch.\*.remote configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin. (This behavior matches git fetch as well—unsurprisingly, since they use the same bit of source code to get that result.* – phd Sep 18 '18 at 23:14
  • Thank you. Being unfamiliar with git source code , I was unaware how to link it with git fetch. @phd , pls post it as answer so that I can accept it. Many beginners like me wont be able to find this answer in torek answer. So, I dnt want to mark duplicate. – Number945 Sep 18 '18 at 23:22

2 Answers2

0

Fetch talks about an upstream branch configured for the current branch.

Doing git help config and searching for "upstream" gets me

   branch.<name>.merge
       Defines, together with branch.<name>.remote, the upstream branch
       for the given branch. It tells git fetch/git pull/git rebase which
       branch to merge and can also affect git push (see push.default).
       When in branch <name>, it tells git fetch the default refspec to be
       marked for merging in FETCH_HEAD. The value is handled like the
       remote part of a refspec, and must match a ref which is fetched
       from the remote given by "branch.<name>.remote". The merge
       information is used by git pull (which at first calls git fetch) to
       lookup the default branch for merging. Without this option, git
       pull defaults to merge the first refspec fetched. Specify multiple
       values to get an octopus merge. If you wish to setup git pull so
       that it merges into <name> from another branch in the local
       repository, you can point branch.<name>.merge to the desired
       branch, and use the relative path setting .  (a period) for
       branch.<name>.remote.
jthill
  • 55,082
  • 5
  • 77
  • 137
0

As @phd posted in the comments and as verified by @torek in the comments in reference link, I am posting answer on their behalf.

When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch which means if there is a remote tracking branch configured for that branch , then it will have the branch.<currentBranchName>.remote config value which it will consult.

The behaviour is similar to git push for finding the repository when not mentioned explicitly.

Number945
  • 4,631
  • 8
  • 45
  • 83