How to use Git and GitHub in Ubuntu [Installation, Configuration]
Update: If you are trying to access Git with the password (as you were accessing it earlier), you will see the authentication error “fatal: Authentication failed”. Support for password authentication was removed on August 13, 2021. You have to use the personal Git access authentication token to use Git.
In this tutorial, I’m going to demonstrate the steps for setting up the Git and GitHub on Ubuntu for your project. With these simple steps, you can set up git on any Linux distro.
Step1: Generate Personal Git Token
GitHub is one of the most popular DevOps tools. There are many alternatives, though.
Follow the steps to generate a personal Git access token on GitHub.
- Log into GitHub with your username and password.
- In upper right corner, click on your name / avatar and select Settings.
- From left sidebar, select Developer settings
- Click on Personal access tokens and then Generate new token
- Add some description or name to the token and select the scope.
- If you are only interested to access your repo, select only repo. With this you can perform basic repo actions like pull, push, clone, and commit.
- Now click Generate token
- Copy your personal git access token.
That’s is all. The token is going to be your new password!
Step 2: Configue Local Git
You don’t need to install anything to use Git on Ubuntu. By default, Ubuntu supports Git.
Set your git account locally on your Ubuntu (Linux OS) system. There are two basic configurations that you need to set i.e. name and email. Here are simple commands.
Important: In the below command, add your name and email inside brackets. First, two commands are to set up the name and email. With the third command, you can check if your configuration parameters are set properly.
git config --global user.name "" git config --global user.email "" git config -l
Step 3: Clone Your GitHub Repo
If you have a repo on GitHub, you can clone it.
git clone <git-repo-url>
You will be asked to enter the username and password. Provide a token as your password.
Step 4: Setup Git Username and Password Credentials
If you don’t set up or configure username and password, git will ask you to enter username and password every time you try to pull or push the code. This will be really frustrating.
If you want to avoid providing a username and password every time, you can just store that username and password.
Run the following command.
git config --global credential.helper store
Now when you try to connect to the remote repo, you will be asked for the username and password. This time your username and password will be saved so that you don’t need to provide a username and password again.
Note: This command saves the username and password in plain text format on your disk.
You can check the configuration in the file
The username and password will be saved in the file
~/.git-credentials. in the format
You can check that with the command
You can also opt for cache to store the username and password instead of disk.
git config --global credential.helper cache
This is more secure than storing credentials on a disk.
Step 5: Set Origin URL
This is an alternative step to step 4.
You can also set the origin URL for your remote git access.
git remote set-url origin <new_git_repo_url_with_toekn>
The format for the new_git_repo_url_with_toekn is
Some of the related articles I have written and you might like reading them.
That is all. With these simple steps, you learn how to use Git in Ubuntu.