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:
- Go to the original repository that you have cloned.
- 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:
-
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
-
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.