“git push” doing the same as “git fetch” from the remote

送分小仙女□ 提交于 2019-12-11 01:29:29

问题


My question is the same as this one, but the answer is not clear to me. I have two git repos A and B in sync (corresponding to the two machines I work on). When I start working in B, I would normally do git fetch A (assuming the remote A in B points to repo A). But I want instead being able to push from A to the remote branch A inside B whenever I work in A. I want to be sure that it is safe, because of the warnings concerning pushing to a non-bare repo. My settings (in file A/.git/config) would be:

[remote "B"]
fetch = +refs/heads/*:refs/remotes/B/*
push =  +refs/heads/*:refs/remotes/A/*
url = ssh://<machine_B>/home/project/B

With this setting, do I get exactly the same result with this two commands? :

  • in A: git push B
  • in B: git fetch A

回答1:


If you do git push B in A, you already update refs in B (only the ones you actually pushed), so that a subsequent git fetch A in B is not be required to update the specific updated refs.




回答2:


I found the exact answer to my question on kerneltrap mail archive, by one of the main git developpers. So yes, both commands are equivalent.



来源:https://stackoverflow.com/questions/4239064/git-push-doing-the-same-as-git-fetch-from-the-remote

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