做空者:有没有一种方法可以让git回购推送到远程回购列表(而不是一个单一的“来源”)中并从中提取?
长篇大论:当我在多台电脑上开发一个应用程序时,我经常会遇到这样的情况,这些电脑具有不同的连接能力——比如,一台笔记本电脑在运输途中,一台电脑“a”在某个位置,另一台电脑则“B”在另一台位置。此外,笔记本电脑可能只与“A”或“B”连接,有时两者都连接。
我希望git始终“拉”到它当前可以连接的所有计算机,这样从一台机器跳到另一台机器,继续无缝工作就更容易了。
做空者:有没有一种方法可以让git回购推送到远程回购列表(而不是一个单一的“来源”)中并从中提取?
长篇大论:当我在多台电脑上开发一个应用程序时,我经常会遇到这样的情况,这些电脑具有不同的连接能力——比如,一台笔记本电脑在运输途中,一台电脑“a”在某个位置,另一台电脑则“B”在另一台位置。此外,笔记本电脑可能只与“A”或“B”连接,有时两者都连接。
我希望git始终“拉”到它当前可以连接的所有计算机,这样从一台机器跳到另一台机器,继续无缝工作就更容易了。
当前回答
使用以下命令向全局gitconfig(/home/user/.gitconfig)添加别名。
git config --global alias.pushall '!f(){ for var in $(git remote show); do echo "pushing to $var"; git push $var; done; }; f'
一旦你提交代码,我们说
数字推送
默认情况下推送到原点。在上面的别名之后,我们可以说
git推球
并且代码将被更新到所有远程设备,包括原始远程设备。
其他回答
自git1.8(2012年10月)以来,您可以通过命令行执行此操作:
git remote set-url origin --push --add user1@repo1
git remote set-url origin --push --add user2@repo2
git remote -v
然后git push将推到user1@repo1,然后推到user2@repo2.
我想在VSO/TFS中工作,然后在准备好后向GitHub公开推送。在私人VSO中创建的初始回购。当需要添加到GitHub时,我做到了:
git remote add mygithubrepo https://github.com/jhealy/kinect2.git
git push -f mygithubrepo master
像冠军一样工作。。。
要进行健全性检查,请发出“gitremote-v”以列出与项目关联的存储库。
C:\dev\kinect\vso-repo-k2work\FaceNSkinWPF>git remote -v
githubrepo https://github.com/jhealy/kinect2.git (fetch)
githubrepo https://github.com/jhealy/kinect2.git (push)
origin https://devfish.visualstudio.com/DefaultCollection/_git/Kinect2Work (fetch)
origin https://devfish.visualstudio.com/DefaultCollection/_git/Kinect2Work (push)
简单的方法,对我有用…希望这能帮助到某人。
我将两个单独的pushurl添加到.git配置文件中的远程“源”。当我运行git push origin“branchName”时,它将运行并推送到每个url。不确定是否有更简单的方法来实现这一点,但这对我自己来说是可行的,既可以推送Github源代码,也可以推送My.visualStudio源代码。
[remote "origin"]
url = "Main Repo URL"
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = "repo1 URL"
pushurl = "reop2 URl"
使用现代版本的git,不再需要手动执行此操作!见下文Malvineous的解决方案。
此处转载:
git remote set-url origin --push --add <a remote>
git remote set-url origin --push --add <another remote>
原答覆:
这是我用了很长时间没有坏后果的东西,是Linus Torvalds在git邮件列表中建议的。
araqnid的解决方案是将代码引入存储库的合适解决方案……但如果你和我一样拥有多个同等的权威上游(我将一些更关键的项目克隆到私有上游、GitHub和Codaset),那么每天都要对每个项目进行更改可能会很痛苦。
长话短说,gitremote单独添加所有远程……然后git-config-e并添加一个合并的远程。假设您有此存储库配置:
[remote "GitHub"]
url = git@github.com:elliottcable/Paws.o.git
fetch = +refs/heads/*:refs/remotes/GitHub/*
[branch "Master"]
remote = GitHub
merge = refs/heads/Master
[remote "Codaset"]
url = git@codaset.com:elliottcable/paws-o.git
fetch = +refs/heads/*:refs/remotes/Codaset/*
[remote "Paws"]
url = git@github.com:Paws/Paws.o.git
fetch = +refs/heads/*:refs/remotes/Paws/*
…要为“Paws”和“Codaset”创建一个合并的远程,我可以在所有这些之后添加以下内容:
[remote "Origin"]
url = git@github.com:Paws/Paws.o.git
url = git@codaset.com:elliottcable/paws-o.git
一旦我做到了这一点,当我按下Origin Master时,它将按顺序推送到Paws/Master和Codaset/Master,这让生活变得简单了一点。
添加新远程
git remote add upstream https://github.com/example-org/example-repo.git
git remote -vv
从多个位置提取
git fetch --all
推送至位置
git push -u upstream/dev