首页 > 解决方案 > 是否可以创建整个团队都可以使用的存储库的分支(而不是个人分支)?

问题描述

我们的代码库都是关于集成到我帮助支持的这个供应商平台中。我们即将进行主要版本升级,这将需要几个月的时间。但是,虽然我们正在进行升级测试/修复,但我们当前的版本仍有正在进行的项目/增强功能。

所以我们有一个想法,也许是创建一个“新版本”特定的分支,它将与当前的开发分支(用于“旧版本”)同步。但是,我只知道如何创建个人分叉。有没有办法创建一个整个团队都可以使用并具有强制同步功能的基于项目的分支?我能想到的唯一选择是根据当前分支创建一个新分支,并每隔一段时间手动拉入它。

标签: gitrepository

解决方案


精简版

# 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.githttps://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 上进行提交

将更新带到MyRepoForkfromMyRepoOrigin

添加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 pullupstream存储库和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

参考


推荐阅读