my git push command always prompts for username and password.
Can't I put it in environment variables or something to not having to enter it again and again?
I am using Ubuntu and repo is on GitHub
I prefer this Option 2: Use Git Credential Helper (HTTPS but cached)
What happens when my PAT changes after 90 days?
Good question—this is exactly where people get tripped up with HTTPS + PAT 👍
🔄 What happens when your PAT expires?
When your Personal Access Token (PAT) expires (e.g., after 90 days on GitHub):
👉 Next git push:
-
Git tries using the old cached token
-
GitHub rejects it ❌
-
You’ll see something like:
remote: Invalid username or password
fatal: Authentication failed
🧠 What Git does internally
If you're using:
1. credential.helper store
-
Old PAT is saved in:
~/.git-credentials -
Git keeps using it → keeps failing until you replace it
2. credential.helper cache
-
Stored in memory only
-
Once expired → you’ll be prompted again automatically
👉 This is why cache is smoother for PAT rotation.
🛠️ How to fix when PAT expires
Option A: Just retry push (simplest)
Bashgit push
-
It will prompt again
-
Enter:
-
Username: your GitHub username
-
Password: new PAT
-
👉 Git updates stored credentials automatically (for both store and cache)
Option B: Manually remove old credentials (if stuck)
If Git keeps failing without prompting:
For store:
Bashnano ~/.git-credentials
Delete the line with GitHub credentials.
Or:
Bashrm ~/.git-credentials
Then:
Bashgit push
Option C: Force Git to forget credentials
Bashgit credential reject
Or:
Bashgit config --global --unset credential.helper
git config --global credential.helper store
🔐 Best Practice for You
Since you're on Ubuntu and want low friction:
👉 Recommended setup:
Bashgit config --global credential.helper cache
git config --global credential.helper 'cache --timeout=86400'
-
24-hour memory cache
-
No file storage
-
Smooth re-auth when PAT changes
⚡ Pro Tip (Optional but powerful)
Instead of expiring tokens every 90 days:
👉 When creating PAT on GitHub:
-
Choose longer expiry (or no expiry if allowed in your org)
-
Scope:
repo(usually enough)
🧭 Summary
| Scenario | What happens | What you do |
|---|---|---|
| PAT expires | Push fails | Re-enter new PAT |
Using store | Keeps failing silently | Delete ~/.git-credentials |
Using cache | Prompts again automatically | Just re-enter |
If you want, I can show you a one-time setup using Git Credential Manager (GCM) which is even cleaner (and handles PAT refresh better).
See All Posts on GitHub <<< Previously
No comments:
Post a Comment