How to use Git and GitHub in Ubuntu [Installation, Configuration]

How to use Git and GitHub in Ubuntu [Installation, Configuration]

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.

git tutorial

Let’s begin.

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.

  1. Log into GitHub with your username and password.
  2. In upper right corner, click on your name / avatar and select Settings.
  3. From left sidebar, select Developer settings
  4. Click on Personal access tokens and then Generate new token
  5. Add some description or name to the token and select the scope.
  6. Now click Generate token
  7. 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 ""
git config --global ""
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 ~/.gitconfig.

vi ~/.gitconfig

The username and password will be saved in the file ~/.git-credentials. in the format

https://git-user:[email protected]

You can check that with the command

vi ~/.git-credentials

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.

Leave a Reply

Your email address will not be published. Required fields are marked *