您正在尝试将集中式工作流程应用于分布式系统。你需要考虑在本地做事,而不是集中做事。共享(中央)存储库只是您放置想要与他人共享的内容的地方,或者您检索他们想要共享的内容的地方。
这基本上就是您所要求的。但是,我认为这不是最好的工作流程。请参阅下面的修改版本。
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
但是……整个工作流程都围绕着遥控器作为“真相的来源”。更多的 git 方式,恕我直言,将您的本地视为真相的来源,并使用中央存储库中的共享内容对其进行更新。都是一样的,只是从不同的角度来看。
以下是我如何处理您的工作流程:
创建一个新的本地分支 (A) 来跟踪远程分支 (X) git clone my_repo 做一些工作,做一些本地提交。工作,工作工作 git add 。git commit -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
当然,这两种情况都取决于您在将 origin/master 重新定位到您的想法分支之前没有在本地 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)