Git

GitHub Clone With OAuth Access Token

GitHub is one of the famous code managing platforms that enables developers to manage their DevOps project on a server through the remote repository. Git users can clone the GitHub repository into a Git local repository. More specifically, the public repository can be directly cloned through a URL. However, Git users can utilize the OAuth protocol for secure designated access along with a repository URL for cloning GitHub repositories.

This write-up will demonstrate how to clone GitHub with an OAuth access token.

How to Clone GitHub With OAuth Access Token?

The OAuth access token requests the server’s APIs for authorization on users’ will. GitHub tokens are utilized to access GitHub and its repositories completely. In order to clone GitHub through the OAuth access token, the below-provided procedure is good enough.

Step 1: Open GitHub Settings

First, open the GitHub official website. Then, click on the “Profile” icon, and select the “Settings” option:

Step 2: Open Developer Settings

Navigate to the “Developer settings”:

Step 3: Generate GitHub Token

Next, click on the “Personal access tokens” drop-down menu, and select the “Token” option. After that, hit the “Generate new token” button:

Add a note or name of the token in the “Note” text field. Mark the checkboxes of GitHub components you want to clone through the OAuth access token. For instance, we have marked the repo to clone the GitHub repository:

After that, hit the “Generate token” button to generate the GitHub token:

From the below output, you can see we have successfully generated the GitHub OAuth token:

Note: Copy the token in any text editor or save it somewhere for later use.

Step 4: Launch Git Bash Terminal

Next, open the Git Bash terminal from the Windows Start menu:

Step 5: Open Git Repository

Navigate to the Git repository in which you want to clone GitHub using the “cd” command:

$ cd "C:\Git"

Step 6: Clone GitHub

Next, clone the GitHub repository using the “git clone” command. In the URL, attach the token you have generated in Git. For this purpose, we have provided URL syntax:

https://oauth2:<token>@github.com/<Username>/<repository>.git

In our case, we have utilized the below command to clone the GitHub “demo1” repository:

$ git clone https://oauth2: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@github.com/GitUser97/demo1.git

The output indicates that we have successfully cloned the GitHub with an OAuth access token:

We have elaborated on how to clone GitHub with an OAuth access token.

Conclusion

To clone GitHub through the OAuth access token, first, navigate to the GitHub official website. Next, from the “Developer settings” under the GitHub settings, generate the OAuth token. After that, open the Git bash terminal, and clone the GitHub repository using the “$ git clone <URL>” command. In the URL, specify the OAuth token, GitHub username, and repository name. This blog has elaborated on the method for cloning a GitHub with an OAuth access token.

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.