我怎么能把它放到“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
How can I have it to where "git push" pushes to local repositories?
提问by ForeverConfused
I can do git remote add origin x@x:~/blah
and git push
will work. But if I create a local copy git clone ~/blah
inside /var, then git remote add local /var/blah
inside ~/blah
, when I try git push
it 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 clone
inside 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 pull
to get the updates? How can I say git push
to push code to all libraries?
我有一个在一堆项目中使用的共享库。我git clone
在其他文件夹中使用来获取库的本地副本。当我更新主库时,我必须转到每个本地副本并键入git pull
以获取更新?我怎么能说git push
将代码推送到所有库?
回答by Grant Limberg
By default, git push
pushes 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 local
to 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 all
to 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 本身将被更新,但检出(磁盘上)文件将不会更新。