How to Log into Git CLI for GitHub: Step-by-Step Guide

Monazir Muhammad Doha | Nov 22, 2023 min read

To seamlessly push changes without constant password prompts, follow these steps:

1. Generate a Personal Access Token on GitHub:

  1. Navigate to the “Developer settings” tab in your GitHub account settings.
  2. Select “Personal access tokens.”
  3. Then Select Token(classic) because as of now, the other one is still in beta.
  4. Click “Generate new token.”
  5. Provide a name, select necessary scopes, and click “Generate token.”
  6. Safely copy your token.

2. Login To Git:

Run the following commands to open and modify the Git configuration file:

git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git config --global credential.helper "store --file ~/.git-credentials"
echo "https://github.com:[email protected]" >> ~/.git-credentials

Replace YOUR_ACCESS_TOKEN with your personal access token.

3. Push Changes Without Password Prompts:

git push origin main

You shouldn’t encounter any password prompts. If you do, double-check your Git configuration to ensure it’s accurate.

It’s essential to acknowledge that both methods, utilizing SSH keys or an access token, provide secure authentication with Git. However, SSH keys are generally regarded as a more secure option.