Creating Your Remote Repository Using a GitHub API Access Token
This brief tutorial proposes an alternative to the original method of linking your remote repository. You are here because you’ve been redirected from either Lab 3 or Lab 4 / Part 2
In this tutorial, we’ll be:
- Creating a GitHub API access token to use on the command line, and
- Using this token to run a CURL command that will create your new REMOTE repository with the same name you gave to your LOCAL.
1. Create a GitHub API Access Token
From the top-right corner of your GitHub page, click on your avatar and select Settings from the dropdown list:
On the next page, there is a left sidebar. Scroll down and click on the Developer Settings button:
On the next page, do the following:
- Click on Personal access tokens from the left sidebar, and
- Click the Generate new token button on the right:
The next page is called “New personal access token.” We’re going to create a token, or a number that will allow us to access the GitHub API from the command line. We’ll use this instead of our GitHub password to authorize ourselves when we link our remote repository, as we’ll see later. On this page, do the following:
- Click the repo checkbox, which will automatically check all the related checkboxes below it. We’re going to use this access token for creating repositories, so we want to be sure this category has been enabled.
- Type a note that you’ll recognize. You’ll only get to see the token once, and after that you’ll only have this note to recognize your token by!
Now, scroll down to the bottom of this page and click the green Generate token button:
On the next page, you’ll see your new API token value — a long string of characters — appear in a green frame. Notice the warning that reads, “Make sure to copy your personal access token now. You won’t be able to see it again!” Notice that there is also a clipboard icon next to your token value. Click the token icon to copy your token to the clipboard:
Finally, paste this token value somewhere for safe keeping. For example, you can create a text file and save the token inside it. Keep the token (and the token note that you created above) wherever you can easily access it.
This is your personal API token; don’t share it with anybody! We’ll use it instead of your GitHub password in the steps that follow, so don’t lose your token!
2. Create Your New REMOTE Repo
Copy your token value to the clipboard (if you haven’t just done it in the previous steps). Now, we are ready to link our local and remote repositories using the access token we’ve just created.
In Terminal, resuming just where we’d paused our work in either Lab 3 or Lab 4 / Part 2, type the following long command:
Replace the fake API token (38597e1f2g1az2h5870fs6i465rty5w234c97qqq) with the token you created, copied, and saved on your own GitHub page. This is the equivalent of using your GitHub password to “log in” to the GitHub API from the command line.
When you’re ready, press <ENTER>
to run the command.
You’ll see A LOT of text printed to the console…
Follow the link printed towards the top under “location:” to verify that your new remote repository is working on GitHub. It should follow the general pattern of https://github.com/yourUserName/lab-03-git-intro.git. When you see the name of the repository online, you know it worked:
Congratulations! You’ve successfully created your new remote repository (on GitHub) and you’re now ready to link it to your local repository, and finally you’ll be able to git commit
and git push
from the command line!
Once you’ve completed the steps in this tutorial, return to the tutorial you are actively working on: either Lab 3 or Lab 4 / Part 2 exactly where the link to this tutorial appears, and resume work on your lab.