git - 是否可以创建整个团队都可以使用的存储库的分支(而不是个人分支)?
问题描述
我们的代码库都是关于集成到我帮助支持的这个供应商平台中。我们即将进行主要版本升级,这将需要几个月的时间。但是,虽然我们正在进行升级测试/修复,但我们当前的版本仍有正在进行的项目/增强功能。
所以我们有一个想法,也许是创建一个“新版本”特定的分支,它将与当前的开发分支(用于“旧版本”)同步。但是,我只知道如何创建个人分叉。有没有办法创建一个整个团队都可以使用并具有强制同步功能的基于项目的分支?我能想到的唯一选择是根据当前分支创建一个新分支,并每隔一段时间手动拉入它。
解决方案
精简版
# Display url remote
$ git remote -v
# Add remote
$ git remote add upstream https://github.com/ <URLRepoOrigin>
## - Where upstream is the name of the remote
# Bring changes from the main fork
$ git pull upstream master
## - Where master is the name of the branch from where we want to bring the changes from the Origin Repository and the name of the remote is upstream
# Upload them to our fork
$ git push origin master
## - Where master is the name of the branch to which we want to upload the changes of our Fork Repository and the name of the remote is origin
扩大的视野
upstream
让你的 fork 与git同步
假设我们在 [GitHub] ( https://github.com/ )中创建了一个项目的分支(名称https://github.com/MyRepoFork/app.git
为https://github.com/MyRepoOrigin/app.git
通常称为上游。
Forkeado 存储库克隆过程
接下来,我们将从克隆和伪造的存储库开始。
知道您可以从本地工作副本连接和同步(跟踪)一个或多个远程存储库,请记住,当克隆存储库时,默认情况下它连接到克隆它的存储库(在我们的例子中是 forkeado):
$ git remote -v
origin https://github.com/MyRepoFork/app.git (fetch)
origin https://github.com/MyRepoFork/app.git (push)
每个remote repository
都有一个关联的名称。默认情况下,将调用从中克隆工作副本的源存储库。origin
从我们的存储库克隆后,我们可以在 fork 上进行提交。
将更新带到MyRepoFork
fromMyRepoOrigin
添加remote
现在,为了能够在我们的 fork ** 中更新原始项目中所做的更改,有必要在我们的本地工作副本 (MyRepoFork)中添加远程存储库** ( connect ) 。
为此,我们将使用以下命令将其与 url 和我们将提供给远程存储库的名称连接起来git remote
:
$ git remote add upstream https://github.com/MyRepoOrigin/app.git
按照约定,该名称upstream
用于命名与我们伪造的项目对应的存储库:
$ git remote -v
origin https://github.com/MyRepoFork/app.git (fetch)
origin https://github.com/MyRepoFork/app.git (push)
upstream https://github.com/MyRepoOrigin/app.git (fetch)
upstream https://github.com/MyRepoOrigin/app.git (push)
这样就origin
对应了我们fork ( MyRepoFork
)upstream
的repository,也对应了原项目的repository ( MyRepoOrigin
)。
更新做pull
最后,为了带来最新的更新,upstream
从而使我们的 fork 保持更新,请git pull
在upstream
存储库和master
分支上运行(默认为分支,或指定不同开发的另一个分支):
$ git pull upstream master
去我们的回购
然后可以通过执行推送将这些更改上传到我们的 fork :
$ git push origin master
更多信息
有关更多信息,请查看以下手册页:
man git-clone man git-remote man git-pull man git-commit man git-push
参考
推荐阅读
- javascript - 元素输入类型=文本无法输入越南语
- android - 如何将 Single observable 运算符与 Location 对象一起使用
- android - 关于 Android 的 build.gradle 中的 Google Play 服务库的错误
- sql-server - SQL - 如果不存在则插入表中 - 使用现有的 NULL 值
- c# - TSQL 多个连接与来自 ASP.NET Core 的多个请求?
- pandas - 使用 iloc 从另一个查找数据帧
- javascript - 当用户点击提交按钮时,带有 JavaScript 的 Sweetalert 弹出消息
- python - 安全皇后问题是否有恒定时间解决方案?(python)
- laravel - 如何在 Laravel 5.8s 内置身份验证中验证用户角色?
- javascript - 哪些 url 数据应该使用 restapi 添加到 ajax 数据中