Cloning a private repository on GitHub can be a bit more involved than cloning a public one, but with the right steps, you can get it done quickly and securely. In this article, we’ll walk you through the process of cloning a private GitHub repository using a personal access token.
Step 1: Create a Personal Access Token
The first step is to create a personal access token (PAT) on your GitHub account. This will allow you to authenticate with GitHub without using your username and password directly.
Create a Personal Access Token
Go to your GitHub account settings.
Click on “Developer settings” in the left sidebar.
Click on “Personal access tokens” and then on “Fine-grained token.”
Give your token a descriptive title and select the necessary permissions, such as “Commit statuses,” “Contents,” and “Pull requests” with Read and Write access.
Click “Generate token” to create your new personal access token.
Step 2: Clone the Private Repository
Now that you have your personal access token, you can use it to clone the private repository.
Clone the Private Repository
Open your terminal or command prompt.
Navigate to the directory where you want to clone the repository.
Run the following command, replacing with your GitHub username and with the token you just created:
textgit clone https://:@github.com/owner/repo_name.git
If prompted, enter your GitHub username and use your personal access token as the password.
Alternatively, you can also clone the repository and let Git prompt you for your username and password. When prompted, use your username and your personal access token instead of your regular password.