Git

How to Clone a GitHub Private Repository in Git

Cloning is one of the important and useful features of Git that allows users to create a copy of the Git repository in another directory. Git users can add and copy the Git remote and local repositories. More specifically, the remote repositories are accessible on the server, and most users use GitHub for creating and managing remote repositories. However, some developers may think that cloning a private repository into Git slightly differs from cloning the public repository in Git.

This post will specifically demonstrate the method to clone a GitHub private repository.

How to Clone a GitHub Private Repository in Git?

To clone the GitHub private repository, first, open the GitHub account and copy the private repository URL. After that, open the Git terminal and utilize the “git clone URL” command.

To clone a private repository in Git, go through the mentioned procedure.

Step 1: Open GitHub Private Repository

Open the GitHub official website and open the private repository:

Step 2: Copy Repository URL

From the “Code” menu, copy the “HTTPS” URL as highlighted below:

Step 3: Launch Git Terminal

Launch the Git terminal by searching “Git Bash” in the Start menu:

Step 4: Go to Git Repository

Go to the Git repository using the “cd <repository-path>” command:

$ cd "C:\Git\Test"

Step 5: Initialize the Repository

Initialize the Git local repository through the given repository:

$ git init

Step 6: Clone Private Repository

Clone the GitHub private repository with the help of the below command. The syntax of the URL should be as follows:

https://<username>@github.com/<username>/<repository-name>.git

To clone the private repository, we will execute the “git clone <Repository-URL>” command:

$ git clone https://[email protected]/GitUser97/Test.git

We have learned the method to clone GitHub’s private repository in Git.

Conclusion

To clone the GitHub private repository, first, open the GitHub official website and open the repository you want to clone. Next, copy the repository URL from the repository code. After that, open the Git terminal, go to the repository where you want to clone the private repository, and utilize the “git clone URL” command having the URL pattern as “https://[email protected]/username/repository-name.git”. This post has elaborated on the method to clone a private repository in Git.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.