Login Using The Git Terminal

Last Updated : 26 Feb, 2026

Git uses authentication to securely connect with remote repositories on platforms like GitHub, GitLab, and Bitbucket for collaborative development.

  • Verifies user identity before repository access.
  • Required for clone, pull, and push operations.
  • Ensures secure collaboration on shared codebases

Approach 1: Using HTTPS and Personal Access Tokens (PAT)

Using HTTPS is a simple method, but it requires generating and using Personal Access Tokens (PAT) for secure authentication, as many platforms have deprecated the use of passwords.

Step 1: Clone the Repository

git clone https://github.com/username/repository

If the repository is private, Git will prompt for your username and password.

Example: This is my private git repository now i want to clone this repository. When i try to clone then git will ask me to enter username and password.

git clone https://github.com/rohit-choudhary14/WhatsAppClone
Screenshot-2024-08-17-003406
How to login using the Git terminal

Step 2: Generate a Personal Access Token (PAT)

  • Log in to your GitHub account.
  • Go to Settings > Developer settings > Personal access tokens.
  • Click on Generate new token.
  • Select the scopes or permissions you need.
  • Copy the generated token.
Screenshot-2024-08-17-003820
How to login using the Git terminal

Step 3: Authenticate Using the PAT

  • When Git prompts for your password, paste your PAT instead.
  • Git will remember the PAT for the duration of your session.
token_output
After token is provided you will logged in and repository will start to clone

Step 4: Cache the Credentials

To avoid re-entering your PAT, you can cache your credentials:

git config --global credential.helper cache

Approach 2: Using SSH Keys

SSH keys are a more secure and convenient way to log in to Git. Once set up, SSH keys eliminate the need to enter a username and password for each operation.

Step 1: Generate SSH Key Pair

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

When prompted, press Enter to save the key to the default location, or specify a custom path.

Screenshot-2024-08-17-004900
How to login using the Git terminal

Step 2: Add SSH Key to the SSH-Agent

Start the SSH-Agent in the background:

eval "$(ssh-agent -s)"
Screenshot-2024-08-17-005048
How to login using the Git terminal

Add your SSH private key to the SSH-Agent:

ssh-add ~/.ssh/id_rsa
Screenshot-2024-08-17-005156
How to login using the Git terminal

Step 3: Add SSH Key to Your GitHub Account

Copy the SSH key to your clipboard:

cat ~/.ssh/id_rsa.pub

Navigate to Settings > SSH and GPG keys in your GitHub account.

Click on New SSH key, paste the key, and save it.

Screenshot-2024-08-17-005529
Click on Add SSH key

Step 4: Clone the Repository Using SSH

git clone git@github.com:username/repository.git

Since you've added your SSH key to GitHub, you won't need to enter a username or password.

Approach 3: Using Git Credential Helper

Git Credential Helper allows you to store your credentials securely so that you don't have to enter them each time you interact with a remote repository.

Step 1: Enable the Credential Helper

git config --global credential.helper store

This command will configure Git to store your credentials permanently in a file, or use cache to store them temporarily.

Step 2: Authenticate

  • The first time you perform an operation that requires authentication (e.g., git pull or git push), Git will prompt you for your username and password.
  • After entering your credentials, they will be saved and used automatically for subsequent operations.

Step 3: View or Edit Stored Credentials

  • Your credentials are stored in the ~/.git-credentials file.
  • You can edit this file to remove or update your stored credentials.
Screenshot-2024-08-17-010304
I'm uploading this half screen shot due to security reasons (It shows your login credentials).
Comment
Article Tags:

Explore