Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to duplicate a git repository? (without forking)

Tags:

git

github

People also ask

Can I clone without forking?

Since first you need to fork before cloning, although forking does not come as a strict pre-step for cloning. People of an organization working on a repository do not generally fork the repository.

Can I just copy a git repository?

Yes you can, but there's no need to copy the full working tree. You can copy just the . git folder without the working tree (i.e. as a "bare" repo) and then checkout the latest working tree on the other machine.

Is cloning a repo the same as forking?

The quick answer Forking creates your own copy of a repository in a remote location (for example, GitHub). Your own copy means that you will be able to contribute changes to your copy of the repository without affecting the original repository. Cloning makes a local copy of a repository, not your own copy.


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.


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

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.


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.