Git “Fetch URL” and “Push URL”, whats the difference?

你说的曾经没有我的故事 提交于 2019-12-03 11:19:22
VonC

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.

I think you could use it if you wanted a "staging" repo contributors would push to, and then others would push changes from there to the main repo after review and approval. So you'd fetch from the main repo, and push to the staging repo.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!