手动创建一个Git分支 [英] Manually create a Git fork

查看:66
本文介绍了手动创建一个Git分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我了解分叉,则从概念上讲它涉及以下步骤:

If I understand forking, it conceptually involves the following steps:

  1. 将源存储库镜像克隆到目标存储库
  2. 在目标存储库上设置一个上游"远程服务器,指向源存储库
  3. 其他一些东西,例如电子邮件订阅等(对该问题不重要)

它是这样的:

Original <──upstream─── Forked
(server)               (server)
                           ↑
                           │origin
                           │
                        (local)

与克隆的主要区别在于这些步骤是服务器端,而不是本地步骤.如何在git命令行上手动复制此内容?

The key difference from cloning is that these steps are server-side, not local. How do I replicate this manually, on the git command line?

这是我到目前为止所做的:

Here's what I've done so far:

  1. 将源存储库克隆到本地存储库
  2. 更改原始"遥控器以指向预期的目标存储库
  3. 添加指向源存储库的上游"远程

在此阶段,我已在本地存储库中设置了所有内容.我可以使用中间本地克隆在原始存储库和派生存储库之间进行更改.这就是我所拥有的:

At this stage, I have everything set up on the local repo. I can sync changes between the original and forked repos using an intermediate local clone. So this is what I have:

Original                Forked
(server)               (server)
    ↑                      ↑
    │                      │origin
    │                      │
    └───────upstream─── (local)

现在我如何将该链接推送到服务器,即将原始存储库作为服务器端分叉存储库的上游远程服务器,以匹配第一个图?

Now how do I push this link to the server i.e. make the original repo an upstream remote of the server-side forked repo, to match the first diagram?

请注意,此问题不是特定于GitHub的-我可能还想使用BitBucket来完成此操作.理想情况下,我也应该能够跨站点执行此操作.我在这里已经阅读了很多类似的问题,但是没有明确的答案.

Note that this question is not GitHub-specific - I might also want to do this with BitBucket. Ideally, I should be able to do this across sites as well. I've read lots of similar questions here on SO, but there's no clear answer.

推荐答案

您可以在命令行中使用他们的API在Bitbucket上创建项目,但是您至少需要对源项目具有读取权限.

You can fork a project on Bitbucket using their API on command line, but you need at least read access to source project.

语法是:

curl -v --user {username}:"{password}" \
https://bitbucket.org/api/1.0/repositories/{accountname}/{repo_slug}/fork \
--data "name=mynewrepo"

例如

  1. 要将名称为 ProjectXYZ 的项目 projectABC 从帐户 ABC 派生到您的帐户 XYZ >,请使用以下命令

  1. To fork a project projectABC from an account ABC to your account XYZ with the name ProjectXYZ, use the following command

curl -v --user XYZ:"XYZPASSWORDXYZ" \
https://bitbucket.org/api/1.0/repositories/ABC/ProjectABC/fork \
--data "name=ProjectXYZ"

有关更多详细信息,请参见 Bitbucket文档.

see Bitbucket documentation for more details.

现在在您的本地计算机上克隆此项目,

Now clone this project on your local machine,

git clone your_target_git_repository_path

  • 转到您的项目目录,并添加指向源存储库的远程上游

    git remote add upstream source_git_repository_path
    

  • 现在,随时可以从源存储库(例如从master分支)中提取更改,请使用:

  • Now, at anytime to pull the changes from source repository (say from master branch), use:

    git pull upstream master
    

    并将本地提交推送到服务器上的目标存储库,请使用:git push origin master

    and to push your local commits to your target repository on server, use: git push origin master

    并且当您在目标存储库上的更改准备好与源存储库合并时,请从Bitbucket网站或使用

    And when your changes on target repository are ready to be merged with the source repository, create a Pull Request either from Bitbucket website or using Bitbucket API: Pull Request

    这篇关于手动创建一个Git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆