如果一个项目同时在 GitHub 和 Coding 上都有仓库,能不能一次 commit 就可以更新到两个地方?
PHPz2017-04-21 10:59:35
Git push to multiple warehouses at the same time
To prevent a git repository from being inaccessible due to various reasons, you can push the code to multiple repositories.
Edit the config file in the .git directory under the local warehouse directory.
Add:
[remote "all"]
url = git@github.com:licess/licess.git
url = git@gitcafe.com:licess/licess.git
When push again, run
git push all master
巴扎黑2017-04-21 10:59:35
You can use the git remote set-url command to achieve this, taking Coding and GitHub as examples:
$git remote -v #查看当前远端仓库
origin git@git.coding.net:user/project.git (fetch)
origin git@git.coding.net:user/project.git (push)
github git@github.com:user/repo.git (fetch)
github git@github.com:user/repo.git (push)
$git remote add both git@git.coding.net:user/project.git
# 添加一个名为 both 的远端
$git remote set-url --add --push both git@git.coding.net:user/project.git
# 为其添加 push 到 Coding 的 SSH 地址
$git remote set-url --add --push both git@github.com:user/repo.git
# 为其添加 push 到 GitHub 的 SSH 地址
(Note that if you choose to use SSH to push, you must configure the SSH public key in advance)
You can then use git push both
to push to two remote warehouses at the same time.
PHP中文网2017-04-21 10:59:35
Github supports hooks, you can set them up. Get a server and do this yourself. In this way, every time you push to github, the hook will be triggered to achieve automatic synchronization with gitcafe.