首页 > 解决方案 > Setting a forked repo's pull request default branch

问题描述

Background: I have a project "original" in a VSTS-hosted git repo and wanted to create a similar project, so I forked the repo. I have no intention of merging from the fork to the original repo - they'll be 2 separate projects. The forked repo's master branch policy that requires pull requests, no direct pushes.

Now, whenever I create such a pull request, the default target is not fork>master but original>master. I always manually change it to fork>master, but it's annoying...

Questions:

  1. How can I set the fork repo so that pull requests default to fork>master branch?
  2. How can I convert the forked repo to a "normal" repo, "forgetting" the original repo?

标签: gitazure-devopsgit-fork

解决方案


git fork repo 的目的是为上游(原始)repo 做出贡献。所以分叉回购和原始回购之间总是有关系

如果你想创建一个新的 repo(与原始 repo 没有任何关系),但代码和分支与原始 repo 相同,那么你应该创建一个空的 git repo 并将原始 repo 中的所有分支推送到新创建的存储库,而不是分叉原始存储库。详细步骤如下:

1. 在你的 VSTS 项目中创建一个新的 git repo

在 VSTS 网页中,创建一个新的 git repo。详细步骤,您可以参考使用门户网站创建 repo的文档。

假设 git repo 名称是 myrepo 并且 URL 是https://account.visualstudio.com/project/_git/myrepo.

2. 从本地原始仓库中克隆并签出所有分支

如果您还没有克隆原始 git repo,您​​可以通过以下方式克隆原始 git repo:

git clone <original git repo URL>

然后通过以下命令在本地签出所有远程分支:

git checkout <remote branchname>

3.将本地原始repo的所有分支推送到新创建的repo

在本地原始git repo中,为新创建的git repo添加remote,并将所有分支推送到新创建的git repo。详细命令如下:

#In the local original repo
git remote add myrepo https://account.visualstudio.com/project/_git/myrepo
git push myrepo --all

现在所有分支都被推送到新创建的 git repo 中,并且与原始 git repo 分开。


推荐阅读