正如在 「How can I pull from one remote and push to another with git?」 中提到,您可以:
請注意,你應該重新將您的topic
分支基於upstream/master
(不合並)之上,以便在合併請求中不合並提交。
這意味着git push -f
更新你的叉子遠程分支(將自動更新拉入請求)
可以強制變基既可以通過:
git config autosetuprebase remote
# or
git branch.foo.rebase true
例如:
C:\Users\vonc\prog\git\so>git clone https://github.com/gioele/offlineimap.git
Cloning into 'offlineimap'...
remote: Counting objects: 9445, done.
remote: Compressing objects: 100% (3701/3701), done.
remote: Total 9445 (delta 4962), reused 9445 (delta 4962)
Receiving objects: 100% (9445/9445), 5.75 MiB | 2.18 MiB/s, done.
Resolving deltas: 100% (4962/4962), done.
Checking connectivity... done.
C:\Users\vonc\prog\git\so>cd offlineimap
C:\Users\vonc\prog\git\so\offlineimap>git remote add upstream https://github.com/offlineimap/offlineimap.git
讓我們看看現在主人是指什麼:
C:\Users\vonc\prog\git\so\offlineimap>git branch -avvv
* master 1746676 [origin/master] Make IDLE mode to work again
remotes/origin/HEAD -> origin/master
C:\Users\vonc\prog\git\so\offlineimap>git config --local -l
remote.origin.url=https://github.com/gioele/offlineimap.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
remote.upstream.url=https://github.com/offlineimap/offlineimap.git
remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
讓我們原點爲目的地的推動:
C:\Users\vonc\prog\git\so\offlineimap>git config push.default matching
C:\Users\vonc\prog\git\so\offlineimap>git config remote.pushdefault origin
讓我們改變上游分支:
C:\Users\vonc\prog\git\so\offlineimap>git fetch upstream
remote: Counting objects: 55, done.
remote: Compressing objects: 100% (55/55), done.
remote: Total 55 (delta 25), reused 1 (delta 0)
Unpacking objects: 100% (55/55), done.
From https://github.com/offlineimap/offlineimap
* [new branch] master -> upstream/master
C:\Users\vonc\prog\git\so\offlineimap>git branch -u upstream/master master
Branch master set up to track remote branch master from upstream.
的master
分支被設爲監控upstream/master
:
C:\Users\vonc\prog\git\so\offlineimap>git br -avvv
* master 1746676 [upstream/master: behind 10] Make IDLE mode to work again
現在a git pull
(或b埃特,一個git pull --rebase
)將拉動從upstream
:
C:\Users\vonc\prog\git\so\offlineimap>git pull --rebase
First, rewinding head to replay your work on top of it...
Fast-forwarded master to 6bd76fed5a7e1e24310517b3510c465929870c08.
(和6bd76fed5a7e1e24310517b3510c465929870c08
是upstream/master
提交)
一個git push
仍會推到原點:
C:\Users\vonc\prog\git\so\offlineimap>git push
remote: Permission to gioele/offlineimap.git denied to VonC.
fatal: unable to access 'https://github.com/gioele/offlineimap.git/': The requested URL returned error: 403
(正常的,因爲我不是gioele
,我沒有該回購的寫入權限)
這兩個線程有什麼用處嗎? http://stackoverflow.com/questions/4577874/git-automatically-fast-forward-all-tracking-branches-on-pull和http://stackoverflow.com/questions/4318161/can-git-pull-all-更新,所有我的本地分支。乾杯! – MBlanc
@MBLANC,不是。這些問題涉及一個遙控器,而在這裏我有兩個不同的遙控器:一個遙控器和一個遙控器。儘管如此,感謝您的鏈接,git-up工具看起來不錯。 – gioele