WowBow
WowBow

Reputation: 7593

How do you fork your own repository on GitHub?

I have a public repository on GitHub. I want to replicate/copy it and work on a new project based on this repository, but I don't want to affect how it is now. I tried forking it using the GitHub UI but it didn't do anything.

Upvotes: 297

Views: 101130

Answers (15)

kierandes
kierandes

Reputation: 181

Not sure if this answer was given or not. Though in my case I needed to set permissions on an organization level. For example:

  1. Go to Github > Select your org
  2. Member Privileges
  3. Select 'Allow forking of private repositories'.

If you can't fork it could be this.

Upvotes: 1

Abdul Saleem
Abdul Saleem

Reputation: 10622

STEP BY STEP

First you should create an access token

enter image description here

enter image description here

enter image description here

enter image description here

Then:

Import your existing repository

enter image description here

Here:

Enter a name for your new repository

enter image description here

Now the important step

In the password block, you have to enter the access token that you generated

enter image description here

Upvotes: 1

Akash Mugu
Akash Mugu

Reputation: 323

You can now mark the base repository as a template (in Settings, mark it as a Template repository) and on the main page of the repo, click Use this template to create your second repo.

Creating a repository from a template is similar to forking a repository, but there are important differences[1]:

  • A new fork includes the entire commit history of the parent repository, while a repository created from a template starts with a single commit.[1]
  • Commits to a fork don't appear in your contributions graph, while commits to a repository created from a template do appear in your contribution graph.[1]
  • A fork can be a temporary way to contribute code to an existing project, while creating a repository from a template starts a new project quickly.[1]

Github Help: creating a template repository creating a repository from a template

Upvotes: 19

klaus thorn
klaus thorn

Reputation: 230

  1. create a new empty repo on github webfrontend
  2. in a clone of the older repo, replace the remote and push:
git remote remove origin
git remote add origin [email protected]:account/new.git
git branch -M main
git push -u origin main

This combines the answer of @mcepl with the comment of @wadesworld and is very similar to the official solution shown when creating a fresh repository on github (under the headline "…or push an existing repository from the command line")

Upvotes: -2

VonC
VonC

Reputation: 1324278

I don't think you can fork your own repo.
Clone it and push it to a new repo is good but you need to:

git clone https://github.com/userName/Repo New_Repo
cd New_Repo
git remote set-url origin https://github.com/userName/New_Repo
git remote add upstream https://github.com/userName/Repo
git push origin master
git push --all

(see git push)

See the all process described at "Fork your own project on GitHub".


Six years later (2016), you now have the GitHub importer which allows you to import a repo from another source... including GitHub.
See "Importing a repository with GitHub Importer"

https://help.github.com/assets/images/help/importer/import-repository.png

narf's answer (upvoted) also illustrate that process.

That will allow you to create a new repository and import the full history of the old one into the new one, using its GitHub url.

Again: what you get is a copy, not a real fork: you cannot make pull request from the new repo to the old one.

Again (bis), as stated in the comments by mpersico, this is not a TRUE FORK.

If I have a foo which is the canonical source repo for an open source project that I want other people to fork and have access to do PR, then I do not want to work in that repo, I want a fork I can use to issue proper PRs against my project.
I have solved this my creating a second account in GitHub and forking to that.

Upvotes: 333

FedFranz
FedFranz

Reputation: 1059

Although it is not possible to fork your own repo into the same account, it can be done into an self-owned Organization account, which can be easily created for free via the '+' button.

The main advantage of this option is that the new repo is a real fork of the original one, and not just a clone. This means that you can, for example, update changes in the orginal repo into the new one (which is not the case for a cloned repo).

The only disadvantage I see is that the forked repo won't appear under the user profile but under the organization one.

Upvotes: 30

Nabil_H
Nabil_H

Reputation: 391

Simplest way to achieve the desired effect is to create a new repository, then select the import option and supply the URL of the repo you wish to fork.

Images below will help:

Fork own repo via import-1

Fork own repo via import-2

Upvotes: 6

narF
narF

Reputation: 2204

A super easy way to do it in 30 seconds from the GitHub website:

  1. Copy your repo's URL. Ex: https://github.com/YourName/YourOldRepo (hint: it's the URL when you look at your repo's main page on github.
  2. Click the + icon in the top right corner.
    https://i.sstatic.net/9zJgo.png
  3. Select "Import repository".
  4. Where it asks for the "Old URL", paste the URL you copied at step #1
    https://i.sstatic.net/vgWd3.png
  5. Enter the name of your new repo and click Begin Import.
  6. That's it! You now have a copy of the full repo, with all commit history and branches!

Limitations: It's not actually a real fork. It's a copy of the repo. It won't allow to do pull requests back and forth.

Upvotes: 210

Gino
Gino

Reputation: 1854

When you create a new repo, you can import from another repo with the repo .git url. It took me 30 seconde.

Upvotes: -1

Zuzu Softman
Zuzu Softman

Reputation: 498

For non tech savvy using GitHub, here is one simple solution as an alternative to other great answers above. What you need is just a GitHub Desktop application.

  1. Open your own project repo from browser, and download as a zip, eg your-project-master.zip.
  2. Unzip and rename it as your new repo.
  3. Open GitHub Desktop, and add your new repo by browsing it to your unzipped local path new repo. enter image description here
  4. Publish it to your github, by clicking the publish button. Don't forget to add the name and the description :)

Upvotes: 1

Nick
Nick

Reputation: 3134

The accepted solution of VonC, unfortunately, did not work for me as I got

remote: Repository not found

What did work was the following:

  1. Create a new_repo at github
  2. git clone new_repo
  3. cd new_repo
  4. git remote add upstream old_repo.git
  5. git pull upstream master
  6. git push origin master

I got all the above from here.

Upvotes: 1

shekar
shekar

Reputation: 1271

  1. git clone https://github.com/YOURREPO.git TargetRepoName
  2. cd TargetRepoName/
  3. git remote set-url origin https://github.com/TargetRepoName.git
  4. git push -u origin master

Upvotes: 10

phocks
phocks

Reputation: 3273

I followed these official instructions for "Duplicating a repository" and it seemed to work.

https://help.github.com/articles/duplicating-a-repository/

To create a duplicate of a repository without forking, you need to run a special clone command against the original repository and mirror-push to the new one. This works with any git repository, not just ones hosted on GitHub.

Upvotes: 2

Dominykas Blyžė
Dominykas Blyžė

Reputation: 167

Just tried this, and it worked:

  1. Fork your repo into an organization account
  2. Rename it
  3. Transfer ownership back to yourself

Upvotes: 0

mcepl
mcepl

Reputation: 2786

Just clone it, create new blank repo, and push to it.

Upvotes: 4

Related Questions