This article provided by MiniTool teaches you how to clone/duplicate GitHub Repository in different ways and situations. Learn them one by one and choose the one that suits you most!
What Is GitHub Clone?
In general, when we talk about the GitHub clone, we refer to clone repository GitHub. That is to say, to make a copy of the GitHub repository.
Why Need to Clone GitHub?
When you create a repository of GitHub, it exists as a remote repository. Yet, you are able to clone your repository to a local place on your computer and sync between those 2 locations.
In order to add/move files, fix merge conflicts, and push larger commits easier, you are recommended to clone your repository from the GitHub data center to your local computer.
You can also clone your existing repository or others’ existing repositories to contribute to a project.
How to Clone GitHub Repository?
Cloning your repository pulls down a full copy of all the repository data that GitHub has at that point in time including all versions of every file and folder for the project. You are able to push your changes to the remote repository on GitHub or pull other people’s changes from GitHub.
How to Clone from GitHub by Command-Line?
Let’s go directly to the guide!
Step 1. On GitHub, go to the main page of the repository.
Step 2. Above the files list, click the Code button.
Step 3. There are three options for you to clone repo GitHub.
- Clone with HTTPS
- Use SSH
- Use GitHub CLI
Select the option you need and click the copy icon behind the URL link.
Alt=Clone from GitHub
Step 4. Launch Git Bash.
Step 5. Replace the current working directory with your destination address.
Step 6. Type git clone and paste the link you copied above.
$ git clone https://github.com/username/your-repository
Step 7. Press Enter to create your local repository. Then, wait for the cloning process to complete.
GitHub Desktop Clone Repository
To clone a repository to GitHub desktop, the steps are similar to the way of using commands. The difference is that after you click the Code button, you should choose the Open with GitHub Desktop option to open the repository with GitHub Desktop. Then, click Choose and navigate to the local path via Windows Explorer. Finally, click Clone.
How to Clone an Empty Repository?
There are no files in an empty repository. It is usually created under the condition that you don’t initialize the repository with a README when creating it.
The method for cloning an empty repository is similar to that of cloning a normal repository. And, there are altogether 3 options for you to choose from: Set up in Desktop, HTTPS, and SSH.
How to Duplicate a Repository?
To copy a repository without forking it, you need to run a special clone command and then mirror-push to the new repository.
First of all, you must create the new repository on GitHub by commands of username/new-repository or username/mirrored.
Mirror a Repository
1. Open Git Bash.
2. Make a bare copy of the repository:
$ git clone –bare https://github.com/username/old-repository.git
3. Mirror-push to the new repository:
$ cd old-repository.git
$ git push –mirror https://github.com/username/new-repository.git
4. Delete the temporary local repository you created above:
$ cd ..
$ rm -rf old-repository.git
Mirror a Repository Containing Git Large File Storage Objects
1. Open Git Bash.
2. Make a bare copy of the repository:
$ git clone –bare https://github.com/username/old-repository.git
3. Move to the repository you cloned just now:
$ cd old-repository.git
4. Pull in the repository’s Git Large File Storage objects:
$ git lfs fetch –all
5. Mirror-push to the new repository:
$ git push –mirror https://github.com/username/new-repository.git
6. Push the repository’s Git Large File Storage objects to your mirror:
$ git lfs push –all https://github.com/username/new-repository.git
7. Remove the temporary local repository you created earlier:
$ cd ..
$ rm -rf old-repository.git
Mirror a Repository in Another Location
To mirror a repository in another location as well as get updates from the original, just clone a mirror and periodically push the changes.
1. Start Git Bash.
2. Create a bare mirrored clone of the repository:
$ git clone –mirror https://github.com/username/repository-to-mirror.git
3. Set the push location to your mirror:
$ cd repository-to-mirror.git
$ git remote set-url –push origin https://github.com/username/mirrored
With a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch. So, it will always be the same as the original repository. Setting the URL for pushes simplifies pushing to your mirror. You can update your mirror through the below commands:
$ git fetch -p origin
$ git push –mirror
That is all about the GitHub clone. For more information about the git clone command or its problems, just search on Google for more related articles.