Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git "Fetch URL" and "Push URL", whats the difference?

When would the Fetch URL and Push URL not be the same for a certain remote?

For example, when i run git remote show central for a remote named central, the output looks like:

* remote central
  Fetch URL: [email protected]:/home/aoberoi/Repositories/example.git
  Push  URL: [email protected]:/home/aoberoi/Repositories/example.git
  HEAD branch: master
  Remote branch:
    master tracked

I just don't see why I would be fetching from and pushing to two different URLs, what type of workflow is this intended for?

like image 742
Ankur Avatar asked Dec 17 '10 06:12

Ankur


1 Answers

I am not sure what you mean, since your example includes 2 identical URL, but URLS for push and pull can differ because of:

  • protocol issue: see Git protocols: the url will be slightly different because not every protocol supports push operations (http for instance, except in case of smart http)
  • intermediate repos: you can push to a different repository which will be the "middle man" between the true "central" repo and yours. Certains operations can then be performed (through a post-receive hook for instance), and the commit will then be pushed to the "actual" remote from there if those operations (like "unit testing", "static code analysis" ...) pass successfully.
    For instance of such a usage, see:
    "What is the cleverest use of source repository that you have ever seen?".

That being said, commit 697f652 (Git 2.3.1+, Q1/Q2 2015) by Git maintainer Junio C Hamano (gitster) do mention:

It seems to be a common mistake to try using a single remote (e.g. 'origin') to fetch from one place (i.e. upstream) while pushing to another (i.e. your publishing point).

That will never work satisfactorily, and it is easy to understand why if you think about what refs/remotes/origin/* would mean in such a world. It fundamentally cannot reflect the reality.
If it follows the state of your upstream, it cannot match what you have published, and vice versa.

The documentation wasn't clear that "remote.<nick>.pushURL" and "remote.<nick>.URL" are there to name the same repository accessed via different transports, not two separate repositories.

like image 182
VonC Avatar answered Oct 27 '22 03:10

VonC