您正嘗試將集中式工作流應用於分佈式系統。你需要考慮在本地做事情,而不是集中做事。共享(中央)存儲庫就是您將想要與他人分享的內容,或者檢索他們想要共享的內容的地方。
這裏基本上是你要求的。但是,我不認爲這是最好的工作流程。請參閱下面的修改版本。
Create a new local branch (A) that tracks a remote branch (X)
git clone <url> my_repo
Do some work, make some local commits.
work, work work
git add .
git commit -m "commit of work"
A is rebased up to the HEAD of X. We're operating on the same branch
we want to rebase from the remote, so we can do it all with one command in
this case.
git pull --rebase
Do some work, make some local commits.
work, work work
git add .
git commit -m "commit of work"
Have an offshoot idea, make a new local branch (B) from (A)
git checkout -b idea
Do some work, make some local commits.
work, work work
git add .
git commit -m "commit of work"
B is rebased up to the HEAD of X
git rebase origin master
但是......整個工作流程都圍繞着遙控器作爲「真相的源泉」。做這件事的方式越多,恕我直言就是把你的本地視爲真相的來源,並用中央資源庫中的共享內容來更新它。這是一回事,只是從另一個角度接近它。
以下是我願意做你的工作流程:
創建跟蹤遠程分支(X) 混帳克隆my_repo 做了一些工作新的本地分行(A),使一些地方的提交。 工作,工作工作 git add。 git的承諾-m「提交作品」
A is rebased up to the HEAD of X. We use two commands here, but doing
it this way makes it easy for me to view the differences before
doing the rebase, if I choose.
git fetch
git rebase origin/master
Do some work, make some local commits.
work, work work
git add .
git commit -m "commit of work"
Have an offshoot idea, make a new local branch (B) from (A)
git checkout -b idea
Do some work, make some local commits.
work, work work
git add .
git commit -m "commit of work"
B is rebased up to the HEAD of X
git fetch
git rebase origin/master
當然這兩種方案的取決於你沒有」做基礎重建產地/掌握到你的想法分支之前您的本地master分支額外工作的事實。如果你沒有,你不會有你做了主本地提交,它會更有效地做到:
git fetch
git checkout master
git rebase origin/master --(make sure master is up-to-date locally)
git checkout idea
git rebase master (apply idea on top of the updated local master)
太多的背景下,爲什麼人們喜歡把簡單的問題變成複雜的問題?我大概可以用一句話來提問。 「我如何讓我的本地分支永久跟蹤遠程分支?」 – KurzedMetal
除了「我怎樣才能讓我的本地分支永久跟蹤遠程分支?」顯然不是我問的。 – ipmcc
「我想從本地分支A創建一個分支B,並使它跟蹤A正在跟蹤的同一個遠程分支。我怎麼能在一個命令中做到這一點?有什麼辦法可以將此行爲設置爲默認值?」。更好? – KurzedMetal