DEV Community

Cover image for Even after years in tech, Git authentication can still throw unexpected curveballs! πŸ˜…
Sayista Yazdani
Sayista Yazdani

Posted on

Even after years in tech, Git authentication can still throw unexpected curveballs! πŸ˜…

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"
Enter fullscreen mode Exit fullscreen mode

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:

  1. Generate PAT: GitHub -> Settings -> Developer Settings -> Personal Access Tokens (classic) -> Select repo scope.
  2. Embed Token & Push:
git remote set-url origin https://<YOUR_PAT_TOKEN>@github.com/<username>/<repo>.git
git push -u origin main
Enter fullscreen mode Exit fullscreen mode

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! πŸ‘‡

SoftwareEngineering #WebDevelopment #Git #GitHub #DevOps #CodingJourney #Laravel #FullStackDeveloper #ProblemSolving #TechCommunity

Top comments (0)