Git just told you "failed to push some refs" which tells you absolutely nothing useful. I've debugged this exact error probably 100 times, and it's usually one of these things fucking up your day:
Your Local Branch is Behind (Happens All the Time)
You've been coding in your cave without pulling, which was stupid but we've all done it. Now your push is rejected because your teammates actually committed stuff while you were working.
The error looks like this:
error: failed to push some refs to 'https://github.com/user/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g. 'git pull ...')
hint: before pushing again.
This usually happens when:
- You forgot to pull for a few days (guilty as charged)
- Someone else pushed to the same branch while you were working
- You fucked around with
git reset
on commits that were already pushed
War story: I once went 2 weeks without pulling on a shared feature branch. When I finally tried to push, there were 47 commits ahead of me. Spent 3 hours untangling merge conflicts. Don't be me.
GitHub Killed Your Password (Thanks, Security)
If you're getting Authentication failed
or Permission denied
, it's probably because GitHub killed password authentication in August 2021. Yeah, that was fun to discover at 2am during a hotfix.
remote: Permission denied (publickey).
fatal: Authentication failed for 'https://github.com/user/repo.git/'
Your credentials are fucked because:
- You're still using your GitHub password (doesn't work anymore)
- Your personal access token expired (they do that)
- Your SSH key isn't added to your account
- Two-factor auth is being a pain in the ass
Personal experience: I spent 4 hours debugging what turned out to be an expired SSH key. The error messages were completely useless and I was ready to switch careers.
Merge Conflicts Want to Ruin Your Day
When you try to fix the "behind" issue with git pull
, and both you and your teammate edited the same lines, Git throws a tantrum and makes you manually fix everything.
Auto-merging src/main.js
CONFLICT (content): Merge conflict in src/main.js
Automatic merge failed; fix conflicts and then commit the result.
Git will shit all over your files with these beautiful conflict markers:
<<<<<<< HEAD
// Your brilliant code
const apiUrl = "https://api-v2.example.com";
=======
// Your teammate's "brilliant" code
const apiUrl = "https://api.example.com/v2";
>>>>>>> origin/main
Reality check: Merge conflicts are like taxes - inevitable and annoying. You'll spend way more time resolving them than you think.
Corporate Networks Are the Devil
If you're at a big company, their network probably hates Git. Firewalls block everything that looks remotely useful, and VPNs make everything worse.
Common corporate network bullshit:
- SSH port 22 is blocked (because security theater)
- HTTPS proxy is misconfigured
- VPN routing sends your Git traffic to Narnia
- IT locked down everything and went home
Survival tip: Learn to use SSH on port 443 early. It'll save you when the corporate firewall decides to ruin your day:
git remote set-url origin ssh://git@ssh.github.com:443/user/repo.git
Other Ways Git Can Screw You
Sometimes it's just weird shit:
- The repository got deleted (awkward)
- Branch protection rules block your push
- Large files make Git timeout and die
- Your internet connection is held together with duct tape
Pro tip: Before going down rabbit holes, check if you can access the repo in a browser. Half the time the issue is that simple.
Resources That Actually Helped Me
- GitHub's SSH troubleshooting guide - Only SSH guide that isn't completely useless
- Oh Shit Git - Saved my career more times than I care to admit
- GitHub's non-fast-forward guide - Actually explains what the error means
- Atlassian's merge conflict tutorial - Best visual explanation of conflict resolution
- Git behind firewalls - Corporate network solutions that work
- SSH over HTTPS port - When corporate firewall blocks SSH
- Git authentication failures - Common auth problems and fixes
- Git proxy configuration - Working with corporate proxies
- Personal Access Token guide - Why passwords stopped working
- Git push documentation - Official docs that explain the error messages
- Pushing commits to remote - GitHub's official guide