Introduction
As a programmer using github, you might want to use the terminal to push and pull your code to github. To do so, you need to configure your terminal to be able to access your github account. Today, we take a look at how to make it possible and as easy as it gets. Read along, and as usual, we always help out with your questions.
This tutorial is to help you configure your terminal access to github, not to teach you how to use git/github. So we assume you are familiar with git and github already and just need how to configure access to your github account from the terminal. It’s an advanced tutorial with lots of assumptions.
Procedure
How to configure your username and email for github on your terminal
- To set your username
1
git config --global user.name "NAME"
- To set your email
1
git config --global user.name "[email protected]"
These values above are the values of your github account, if you don’t have an account already, you can create one on github.com for free.
To check the values you have configured
You can use this command below to do so:
1
git config --list
If you notice and error, you can repeat the very commands above and give in the correct values.
Sign into Github on your browser
Clone the repository you want to work with. If there’s no repository already, you can create one and use for your testing purpose.
At this level you have completely configured the basics and have a repository to work with.
At this level if you try to do a git push it will ask for your password but after putting the password, you get an error. This is because the this method of authentication is no longer accepted by github. Below is what you need to do, which is the main purpose of this tutorial today.
Support for password authentication was removed on August 13, 2021
Generate an access token from Github
- Go to github on the browser that you sign in earlier
- Click on your name
- Click on settings
- Scroll down to developer settings
- Click on Personal access token
- Click on Token (classic)
- Next, Generate new token (classic)
- Give a note/name for your token
- Give an expiration date
- Select the scope (all the things that token will be able to do)
- Next click on “generate token”
- Copy the generated token
Adding the generated token to your terminal
Run the command below replacing the values in angled brackets and using the token you generated <>
1
git remote set-url origin https://<TOKEN>@github.com/<USERNAME>/<REPO>
If all is done well you can now push code to your github and do all the actions you selected in your scope in step 10 above. Also, the length of time was selected at step 7 above, so after that amount of time, it will expire.
If it works for you, then that’s great! If it doesn’t work for you then you are probably not respecting the sequence. You can always get in touch with us with your further questions.
Bye for now.
