Even after years in tech, Git authentication can still throw unexpected curveballs! π
Today while pushing the complete codebase for the MBA Pathshala platform to a private GitHub repository, I bumped into a classic developer friction loop:
β error: src refspec main does not match any
β git@github.com: Permission denied (publickey)
β fatal: repository not found
Here is what went wrong and how I resolved it (Sharing for fellow devs facing this!):
1οΈβ£ The Refspec Error: Tried to push before initializing the first commit. Git needs at least one commit to establish the main branch HEAD.
π Fix: Run
git add .
git commit -m "Initial commit"
before pushing.
2οΈβ£ SSH Key Permission Denied: GitHub rejected the default SSH remote URL (git@github.com:...) because my public SSH key wasn't mapped in the account settings.
3οΈβ£ The HTTPS Password Deprecation: Modern GitHub disabled password-based HTTPS authentication for security.
π‘ The Solution:
Switched to HTTPS authenticated via a Personal Access Token (PAT) with repo scopes and embedded it into the remote origin URL:
- Generate PAT: GitHub -> Settings -> Developer Settings -> Personal Access Tokens (classic) -> Select
reposcope. - Embed Token & Push:
git remote set-url origin https://<YOUR_PAT_TOKEN>@github.com/<username>/<repo>.git
git push -u origin main
Result? 264 objects, 10.92 MB codebase uploaded smoothly in seconds! π π οΈ
Building robust production software isn't just about writing codeβit's also about mastering version control workflows and security credentials.
β οΈ Note: Hardcoding PAT in the URL saves it in plain text in .git/config. For better security, consider using Git Credential Manager or fixing your SSH key configuration!
What was the most stubborn Git issue you've faced recently? Drop it in the comments! π
Top comments (0)