Git克隆工作流



作为背景,在一个分叉的工作流中,我克隆并创建了一个分支。

我有以下内容:

Remote:
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)
upstream        https://github.com/stackoverflow/repo.git (fetch)
upstream        no_push (push)

然后,我转到我的分支中的主分支,并通过重基来更新分支:

git checkout master
git fetch upstream
git rebase upstream/master
git push

之后,我在我的分支中找到我的特性分支并更新这个分支:

git checkout feature
git fetch upstream
git rebase upstream/master
git push

最后,当执行push时,我有一个相对于主分支更新的功能分支,并且在顶部包含与功能分支相关的更改。到目前为止一切顺利。

我的问题是如何在没有分叉的情况下遵循类似的工作流?假设您只有以下内容:

Remote:
origin        https://github.com/stackoverflow/repo.git (fetch)
origin        https://github.com/stackoverflow/repo.git (fetch)

你有一个主分支(它将合并来自不同分支的所有更改)和另一个名为feature-2的分支。

在这种情况下,我只需要根据主分支更新feature-2。然后,应该足以执行以下操作(我需要使用rebase将更改包含在顶部)?

git fetch origin
git rebase origin/feature-2
git push

正确吗?

在这种情况下,我只需要根据主分支更新feature-2

那么您需要在更新后的远程master的基础上进行重置:

git fetch origin
git switch feature-2
git rebase origin/master
git push --force

最新更新