我怎么能把它放到“git push”推送到本地存储库的地方?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4694104/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:51:32  来源:igfitidea点击:

How can I have it to where "git push" pushes to local repositories?

git

提问by ForeverConfused

I can do git remote add origin x@x:~/blahand git pushwill work. But if I create a local copy git clone ~/blahinside /var, then git remote add local /var/blahinside ~/blah, when I try git pushit doesn't push the updates.

我可以git remote add origin x@x:~/blah并且git push会工作。但是,如果我git clone ~/blah在 /var 中创建本地副本,然后git remote add local /var/blah在 inside 中创建~/blah,当我尝试时git push它不会推送更新。

How can I make git push updates to local copies?

如何对本地副本进行 git push 更新?

I have a shared library I use in a bunch of projects. I use git cloneinside other folders to get a local copy of the library. When I update the main library I have to go to each local copy and type git pullto get the updates? How can I say git pushto push code to all libraries?

我有一个在一堆项目中使用的共享库。我git clone在其他文件夹中使用来获取库的本地副本。当我更新主库时,我必须转到每个本地副本并键入git pull以获取更新?我怎么能说git push将代码推送到所有库?

回答by Grant Limberg

By default, git pushpushes to origin. If you want to push to a different remote repository (on the same machine or otherwise), you need to do git push <remote-name>. Also keep in mind what mipadi says about non-bare repositories.

默认情况下,git push推送到原点。如果要推送到不同的远程存储库(在同一台机器上或其他地方),则需要执行git push <remote-name>. 还要记住 mipadi 关于非裸存储库的说法。

So in your case, after a git remote add local /var/blah, you would do git push localto push changes to the repo in /var/blah.

因此,在您的情况下,在 a 之后git remote add local /var/blah,您可以git push local将更改推送到 /var/blah 中的存储库。

A little google-fu came up with this post for pushing to multiple remote repositories at once:

一个小小的 google-fu 想出了这篇文章,用于一次推送到多个远程存储库:

http://web.archive.org/web/20110828185858/http://jeetworks.com/node/22

http://web.archive.org/web/20110828185858/http://jeetworks.com/node/22

Essentially, a remote can have multiple urls. To do this edit your .git/config and put something like this:

本质上,一个遥控器可以有多个 url。为此,请编辑您的 .git/config 并输入如下内容:

[remote "all"]
    url = /some/path/to/repo1
    url = /some/path/to/repo2

After that, you can do git push allto push to both of the remote urls pointed to by the remote "all".

之后,您可以git push all推送到远程“all”指向的两个远程网址。

回答by mipadi

Are you pushing to a non-bare repository? If you are, the repo itself will be updated, but the checked-out (on-disk) files will not be updated.

您要推送到非裸存储库吗?如果是,则 repo 本身将被更新,但检出(磁盘上)文件将不会更新。