【问题标题】:Is it possible to avoid using local copies of shared branches in git?是否可以避免在 git 中使用共享分支的本地副本?
【发布时间】:2022-12-12 09:32:45
【问题描述】:

当开始使用 git 时,通常的做法是使用远程共享分支的本地副本,这些副本与远程分支保持同步。例如,以下是遵循此做法的一些常用工作流程:

创建一个新的功能分支

git checkout main
git pull
git checkout -b new-feature-branch

在主分支的最新更改之上进行重新设置

git checkout main
git pull
git checkout new-feature-branch
git pull -r # this works until we change the upstream branch, of course

上游更改后,在 main 的最新更改之上进行 rebase

git checkout main
git pull
git checkout new-feature-branch
git rebase main

是否有可能避免保持分支的本地副本同步,或者更好的是,根本没有本地副本?

【问题讨论】:

    标签: git


    【解决方案1】:

    是的,可以避免远程分支的本地副本必须保持同步。以下是如何在不使用本地副本的情况下完成这三件事:

    创建一个新的功能分支

    git fetch -a
    git checkout -b new-feature-branch origin/main
    

    在主分支的最新更改之上进行重新设置

    git pull
    

    如果您还没有将pull.rebase设置为true,请使用-r...只要我们不更改上游,这就有效

    上游更改后,在 main 的最新更改之上进行 rebase

    git fetch -a
    git rebase origin/main
    

    这样我们就可以避免首先创建 main 的本地副本。

    【讨论】:

      猜你喜欢
      • 2018-02-05
      • 2020-08-11
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 2012-08-21
      相关资源
      最近更新 更多