您正尝试将集中式工作流应用于分布式系统。你需要考虑在本地做事情,而不是集中做事。共享(中央)存储库就是您将想要与他人分享的内容,或者检索他们想要共享的内容的地方。
这里基本上是你要求的。但是,我不认为这是最好的工作流程。请参阅下面的修改版本。
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