[remote "origin"]
url = git@github.com:SegmentFault/XXX.git
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "dev"]
url = git@gitlab.com:root/XXX.git
fetch = +refs/heads/*:refs/remotes/dev/*
config 中配置了两个远程仓库。我想终端下一句 git push 同时把代码提交到两个仓库,该怎么做?
I have used two methods. The first was to set multiple remotes and then write an alias, such as:
Later, after a certain version (forgot the specific version number) was upgraded, Git added an additional setting that allows you to set multiple pushurls for a remote. For example, in the example in your question, I can leave out the
remote "dev"
,只留下remote "origin"
and add:After this, your
remote "origin"
will become a structure similar to the following:In this way, I can directly
git push origin
push two repos.These two methods actually have their own applicable scenarios, so make your own choice.
Since there is a risk of being blocked by a wall, it is a pain in the ass that the two warehouses are out of sync. It’s not too much trouble..
If you really want to do this, just write a shell file.
Then don’t forget to make it executable: (assuming the script is called
push.sh
)Answer: http://blog.codepiano.com/2013/07/03/push-multi-remote-repositories/
The same questions in SegmentFault:
/q/1010000000367632/a-1020000000369754
/q/1010000000411859/a-1020000000411882