How to duplicate a git repository? (without forking)

GitGithub

Git Problem Overview


I have two repositories, and I need to copy whole of one onto the other empty one which has different access levels from the first one. The copy and the mother repository should not be linked together.

I am new to git and it would be awesome if someone could help me with this.

Git Solutions


Solution 1 - Git

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

Short version:

In order to make an exact duplicate, you need to perform both a bare-clone and a mirror-push:

mkdir foo; cd foo 
# move to a scratch dir

git clone --bare https://github.com/exampleuser/old-repository.git
# Make a bare clone of the repository

cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
# Mirror-push to the new repository

cd ..
rm -rf old-repository.git  
# Remove our temporary local repository

NOTE: the above will work fine with any remote git repo, the instructions are not specific to github

The above creates a new remote copy of the repo. Then clone it down to your working machine.

Solution 2 - Git

You can also use git-copy.

Install it with Gem,

gem install git-copy

Then

git copy https://github.com/exampleuser/old-repository.git \
    https://github.com/exampleuser/new-repository.git

Solution 3 - Git

If you are copying to GitHub, you may use the GitHub Importer to do that for you. The original repo can even be from other version control systems.

Solution 4 - Git

If you just want to create a new repository using all or most of the files from an existing one (i.e., as a kind of template), I find the easiest approach is to make a new repo with the desired name etc, clone it to your desktop, then just add the files and folders you want in it.

You don't get all the history etc, but you probably don't want that in this case.

Solution 5 - Git

Update Nov 2021

You can easily copy files and folder of from another VC in github now.

Steps:

  1. Create a new repository
  2. Click on the Import code button at the bottom

Import code

  1. Paste your repository's clone URL and click Begin import

Begin import

You will be notified by email when the import is successfully completed.

Solution 6 - Git

Open Terminal.

Create a bare clone of the repository.

> git clone --bare https://github.com/exampleuser/old-repository.git

Mirror-push to the new repository.

cd old-repository.git

> git push --mirror https://github.com/exampleuser/new-repository.git

Solution 7 - Git

I have noticed some of the other answers here use a bare clone and then mirror push to the new repository, however this does not work for me and when I open the new repository after that, the files look mixed up and not as I expect.

Here is a solution that definitely works for copying the files, although it does not preserve the original repository's revision history.

  1. git clone the repository onto your local machine.
  2. cd into the project directory and then run rm -rf .git to remove all the old git metadata including commit history, etc.
  3. Initialize a fresh git repository by running git init.
  4. Run git add . ; git commit -am "Initial commit" - Of course you can call this commit what you want.
  5. Set the origin to your new repository git remote add origin https://github.com/user/repo-name (replace the url with the url to your new repository)
  6. Push it to your new repository with git push origin master.

Solution 8 - Git

  • You need to copy the link of any repository you need to clone and work on. (here!)

  • click on Import repository from the dropdown by clicking on the + on the top right corner of the Github dashboard. (here!)

  • It will redirect to the import page where you need to paste the repo link in the first input box and type in the name of the new repository. Click on Begin. (here!)

  • It will then again redirect you to another page where it will clone/import the repo to your repos. It will be something like this.

  • It will mail you when the import is completed or you can click on the link underneath to open the new repo.

  • You can continue working on the repo and can click on '.' on the keyboard to activate github developers and then you can continue editing it. (here!)

I hope this answers your query.

d chipmunk

Solution 9 - Git

You can always do it directly on Github which I find it easier. After creating a new repository (child repository) which is empty and you want it to have the same code as the (Parent repository), click on the Code on the top bar. At the buttom, pick the last opion which says (...or import code from another repository). You will be prompted to enter a clone link of the repository you wish to import your code from. Paste the clone link of your (Parent repository) and press import.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioncowboybebopView Question on Stackoverflow
Solution 1 - GitLarry KView Answer on Stackoverflow
Solution 2 - GitQuanlongView Answer on Stackoverflow
Solution 3 - GitMateus GondimView Answer on Stackoverflow
Solution 4 - GittimView Answer on Stackoverflow
Solution 5 - GitAbishek StephenView Answer on Stackoverflow
Solution 6 - GitKundan royView Answer on Stackoverflow
Solution 7 - GitMarco PrinsView Answer on Stackoverflow
Solution 8 - GitchipmunkView Answer on Stackoverflow
Solution 9 - GitDenisView Answer on Stackoverflow