How to turn a cloned repository into a fork?

You cannot directly convert a cloned repository into a fork on GitHub, GitLab or any other git platform, as a fork implies a different type of connection between the original repository and your copy of it. In essence, a fork is a request to the original repository to allow tracking and possible merges of your changes back to the original.

However, here are steps you can follow to manually create a fork from a cloned repository:

  1. Go to the original repository that you have cloned.
  2. Click on the “Fork” button to create a fork of the repository under your GitHub username. Now you have a fork of the original repository.

Let’s say that you have commits in your local clone that you would like to push to the new fork:

  1. On your local system, rename or remove the clone (you might want to back up your commits to another branch or to patch files, if applicable). Then clone the fork to the same location. Now you have a local clone of your new fork.

    # rename the original repository
    git mv original_repo original_repo_backup
    
    # clone the forked repository
    git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY.git
    
  2. If you have changes in the original local clone that you want to have in the new fork, you can push these changes from the old clone to the new fork. Go to the old clone and execute git remote -v to see a list of remote repositories. The output will look something like this:

    origin	https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
    origin	https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
    

    To push the changes, you need to change the origin URL to the fork’s URL. You can do this with the git remote set-url command. Then push the changes:

    # change to the backup repository directory
    cd original_repo_backup
    
    # set new origin URL for the forked repository
    git remote set-url origin https://github.com/YOUR_USERNAME/YOUR_REPOSITORY.git
    
    # push changes to the new fork
    git push origin master
    

This way, the newly created fork would have the same changes as in the cloned repository. Just remember that this method is only needed if you have already made changes to the cloned repository that you want to keep in the fork. If you haven’t made any changes yet, you can just delete the clone and fork the repository.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我想要身体健康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值