If you’re working with Git, you’ll often need to configure a username and password to authenticate with remote repositories like GitHub, GitLab, or Bitbucket. But with increased security requirements, traditional passwords are no longer accepted — especially on platforms like GitHub.
In this guide, you’ll learn how to set your Git username and authenticate securely using a Personal Access Token (PAT) instead of a password.
🎯 What You’ll Learn
- How to set your Git username and email (for commits)
- How to securely authenticate to GitHub using a personal access token
- How to cache credentials for convenience
✅ Step 1: Set Your Git Username and Email (Locally)
Git uses your username and email for commit messages.
git config --global user.name "Your Name"
git config --global user.email "yo*@ex*****.com"
To confirm your settings:
git config --global --list
🔐 Step 2: Authenticate with a Personal Access Token (GitHub)
⚠️ GitHub No Longer Accepts Passwords for Git
You must use a Personal Access Token (PAT) in place of your GitHub password when pushing or pulling via HTTPS.
🛠 How to Generate a PAT:
- Go to your GitHub account.
- Navigate to: Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click “Generate new token”.
- Set an expiration and select scopes like:
repo
(for repository access)workflow
(if using GitHub Actions)
- Click Generate token and copy it (you won’t see it again).
🔄 Step 3: Push Code Using Your Username and Token
When you push code using HTTPS for the first time:
git push origin main
Git will prompt you for credentials:
- Username: your GitHub username
- Password: your personal access token
✅ Tip: Use a credential manager (see next section) to store credentials securely so you don’t have to re-enter them each time.
💾 Step 4: Save Credentials Using Git Credential Manager
To cache your credentials:
git config --global credential.helper cache
Or on macOS:
git config --global credential.helper osxkeychain
On Windows, Git Credential Manager is usually installed by default. To verify:
git config --global credential.helper manager-core
This will store your token securely and auto-fill credentials during future Git operations.
🔧 Optional: Use SSH Instead of HTTPS
For an even more secure setup (and no need to enter a token every time), consider configuring SSH authentication.
ssh-keygen -t ed25519 -C "yo*@ex*****.com"
Then add your public key to your GitHub SSH settings.
✅ Summary
Task | Command |
---|---|
Set Git username | git config --global user.name "Your Name" |
Set Git email | git config --global user.email "yo*@ex*****.com" |
Use PAT for HTTPS | Replace GitHub password with PAT when prompted |
Cache credentials | git config --global credential.helper cache |
📌 Conclusion
While GitHub and similar platforms no longer support passwords for Git over HTTPS, using a Personal Access Token or SSH key ensures your authentication remains secure and seamless. Setting your Git username and email properly is also essential for clean commit history and collaboration.