Reputation: 2345
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.
Upvotes: 165
Views: 183827
Reputation: 31
i don't about your case but mine was that i wanted to fork this repository and for some reasons they wouldn't allow me because saying no location to fork repository and i have another repo that looks exactly like the one i wanted to fork, so here is how i solve my problem.
First Clone the repo you want to fork or duplicate to your vscode or local machine
create a new repository from github dashboard and give it the name you want
now make sure you are inside the clone repo in your local machaine and enter this commands:
git remote add origin https://github.com/YOUR-REPO-URL
git branch -M master
git push -u origin master
if it displays this " fatal: remote origin already exists." after you run the first command above then run this: git remote rm origin then repeat the commands in 3 above.
All your files in the clone repository will be transfered to the newly created repository with different name
Upvotes: 0
Reputation: 11
You need to copy the link of any repository you need to clone and work on.
Click on Import repository from the dropdown by clicking on the + on the top right corner of the GitHub Dashboard.
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.
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.
I hope this answers your query.
Upvotes: 1
Reputation: 545
The quickest option seems to be to enable the template repository option in your repo settings.
Template Repository
Use this template
Template Repository
again.Upvotes: 1
Reputation: 598
Safe version on command line, without need to rewriting origin, for public or private repository.
Create a new repository on github eg: "my-repo-copy"
# Run the command
git clone https://github.com/myprofil/my-repo-copy.git
# The url can be found on the repository, click the button code and https.
# You now have a empty folder my-repo-copy.
# Inside the folder my-repo-copy, run:
git clone https://github.com/myprofil/my-repo-original.git
# You now have a folder my-repo-original, go inside and copy all files/folders except .git
# Go in the folder my-repo-copy and paste, delete the folder my-repo-original
# Run
git add .
git commit -m "clone my-repo-original"
git push origin main
# If you'r branch name is main and you want to be master, after the commit, run
git checkout -b master
git push origin master
Upvotes: 0
Reputation: 7419
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.
git clone
the repository onto your local machine.cd
into the project directory and then run rm -rf .git
to remove all the old git metadata including commit history, etc.git init
.git add . ; git commit -am "Initial commit"
- Of course you can call this commit what you want.git remote add origin https://github.com/user/repo-name
(replace the url with the url to your new repository)git push origin master
.Full steps:
mkdir my-repo
cd my-repo
git clone <repo> .
rm -rf .git
git add . ; git commit -am "Initial commit"
git remote add origin https://github.com/user/repo-name
git push origin master
Upvotes: 0
Reputation: 11
easier and beginner friendly Option: If you want to avoid command lines and terminal to duplicate a repository, this is what you do:
Upvotes: 1
Reputation: 25526
You can also use git-copy.
Note: You need to install Ruby first. Run ruby -v
to check if you have it installed. If you don't:
Linux: run sudo apt install ruby
, Windows: use RubyInstaller, macOS: use Homebrew
Now install git-copy
gem install git-copy
Then you can use it
git copy https://github.com/exampleuser/old-repository.git https://github.com/exampleuser/new-repository.git
Upvotes: 28
Reputation: 1
An easy method using the github GUI. Click on the repository of choice, and within settings then tick template repository. When you navigate back to the main repository. You can then create a direct copy
Upvotes: 0
Reputation: 21
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.
Upvotes: 2
Reputation: 470
Update Nov 2021
You can easily copy files and folder of from another VC in github now.
Steps:
You will be notified by email when the import is successfully completed.
Upvotes: 16
Reputation: 3132
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
Upvotes: -1
Reputation: 3608
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.
Upvotes: 8
Reputation: 5542
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.
Upvotes: 23
Reputation: 49114
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.
Upvotes: 276