How To Login Using The Git Terminal?
Last Updated :
23 Jul, 2025
Git is a widely used version control system that allows developers to collaborate on code. When working with remote repositories hosted on platforms like GitHub, GitLab, or Bitbucket, it's essential to authenticate yourself to perform actions such as cloning, pulling, or pushing code.
This article will guide you through the different methods to log in via the Git terminal, ensuring secure and seamless interaction with your remote repositories.
Various Approaches to Login using the GIt Terminal
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
How to login using the Git terminalStep 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.
How to login using the Git terminalStep 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.
After token is provided you will logged in and repository will start to cloneStep 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 "[email protected]"
When prompted, press Enter to save the key to the default location, or specify a custom path.
How to login using the Git terminalStep 2: Add SSH Key to the SSH-Agent
Start the SSH-Agent in the background:
eval "$(ssh-agent -s)"
How to login using the Git terminalAdd your SSH private key to the SSH-Agent:
ssh-add ~/.ssh/id_rsa
How to login using the Git terminalStep 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.
Click on Add SSH keyStep 4: Clone the Repository Using SSH
git clone [email protected]: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.
I'm uploading this half screen shot due to security reasons (It shows your login credentials).
Explore
Git Tutorial
6 min read
Git Introduction
Git Installation and Setup
All Git Commands
Most Used Git Commands
Git Branch
Git Merge
Git Tools and Integration
Git Remote Repositories
Collaborating with Git