git:当两个人正在更新它(两个远程)时,我如何使用子模块?



我有一个依赖于git子模块的项目。该子模块也是我拥有的存储库,但是从另一个用户的另一个github存储库克隆的。

The layout is:
my_project/
my_submodule/

我想保持我的子模块主分支干净和(可选)同步到其他用户的github存储库(它的主分支也),所以我不搞砸了。但我想在我自己的子模块的那些新分支中创建新的分支和新的提交,这样我就可以将pr发送到github并拥有一个"all_commits"分支保存我对子模块的所有更改,以便我可以使用my_project的最新版本检查更改。基本上我正在寻找这个工作流程:

$ cd my_submodule/
$ git switch main
$ git branch new_pr
$ git checkout new_pr
$ emacs somefile.cpp  # change some file
$ git commit -a
$ git push -u origin new_pr
$ git switch all_commits
$ git merge new_pr     # so all_commits holds all my prs and changes

一旦pr被接受:

$ cd my_submodule
$ git switch main
$ git "sync" to orig_main  # this is the command I am missing
$ git push -u origin main  # store the new_pr change in my own repository
$ git branch -D new_pr     # remove the new_pr now that it was accepted

缺少的一个步骤是用原始存储库("其他用户的github存储库")刷新主分支

$ cd my_submodule/
$ git switch main
$ # if not already done
$ git remote add upstream https://url/other/user/repo
$ git fetch upstream
$ # reset main to the other user's repo main branch
$ git switch -C main upstream/main
$ # create a new PR based on the latest from upstream/main:
$ git switch -c new_pr

最新更新