我想做 git push ,并且应将更改推到两个不同的来源。有没有一种方法可以用git用一个命令将多个来源推向一个以上的角度?一个不错的钩子?
我使用了两种方法来做到这一点。一种方法,当我有一个分叉的存储库时,我会发现方便,并且上游遥控器是在遥控器上使用pushurl
配置选项。对于起源,它看起来像这样:
[remote "origin"]
url = git@github.com:user/repo.git
pushurl = git@github.com:user/repo.git
pushurl = git@github.com:me/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
在叉子存储库中,我在upstream
遥控器中使用pushurl
技巧,并将其推向我的叉子和上游仓库。它有助于使主分支保持同步。
我还使用了我在基础架构上托管的存储库上的接种后钩子,将它们镜像在其他地方(例如github)。后接种后的钩子看起来像:
nohup git push --mirror git@github.com:user/repo.git &> ~/.mirror.log
然后我推到服务器上的存储库,然后服务器推到GitHub克隆。您需要确保正确设置了SSH键,但是除此之外,这很容易。
也许将其添加到您的.git/config
[alias]
push2 = ! git push remote1 && git push remote2