2012-10-25 18 views
2

我想要做一個git push,並且更改應該推送到兩個不同的原點。有一種方法可以通過一個命令與git一起推送到多個原點?一個不錯的勾子也許?將代碼推送至多於一個原點

+0

可能的重複:http://stackoverflow.com/questions/4255865/git-push-to-multiple-repositories-simultaneously –

回答

2

我用兩種方法來做到這一點。我有一個方法,當我有一個分叉存儲庫和一個上游遠程時,我覺得很方便,就是使用遠程上的pushurl配置選項。對於剛剛起源,它會是這個樣子:

[remote "origin"] 
    url = [email protected]:user/repo.git 
    pushurl = [email protected]:user/repo.git 
    pushurl = [email protected]:me/repo.git 
    fetch = +refs/heads/*:refs/remotes/origin/* 

在分叉庫的情況下,我用在upstream遠程的pushurl伎倆,並將它推到我的叉子和上游回購兩種。它有助於讓主分支保持同步,而且不會大驚小怪。

我還在我的基礎架構上託管的存儲庫上使用了後接收掛鉤,以在別處鏡像它們(如GitHub)。後接收鉤看起來是這樣的:

nohup git push --mirror [email protected]:user/repo.git &> ~/.mirror.log 

然後我推到我的服務器上的回購,然後服務器推到GitHub克隆。你需要確保你的SSH密鑰設置正確,但除此之外,這很容易。

+0

謝謝,我使用第二個選項,它工作正常。 – jacksoncage

+0

不客氣! – jszakmeister

0

也許這添加到您的.git/config

[alias] 
push2 = ! git push remote1 && git push remote2 
相關問題