While building my portfolio and a small automation, I ran into a lot of Git errors. Most tutorials show the happy path, so here are the real errors I got, what they meant, and how I fixed each one.

A tip before you start: run one command at a time and read the result. I once pasted two commands on one line (git diff --statgit diff | ...) and got a confusing error.

1. fatal: bad config line 1 in file .git/config

Every Git command failed with this. My .git/config file was empty, so Git could not read it.

Fix: make a copy of your project folder first, then recreate the file with the basics:

[core] repositoryformatversion = 0  filemode = false  bare = false  logallrefupdates = true  ignorecase = true [remote "origin"] url = https://github.com/your-username/your-repo.git  fetch = +refs/heads/*:refs/remotes/origin/* [branch "main"] remote = origin  merge = refs/heads/main 

Then run git status. The first line must be [core], with nothing above it.

2. Author identity unknown

My commit failed because Git did not know who I was.

Fix:

git config --global user.name "Your Name" git config --global user.email "you@example.com" 

Use the email that is linked to your GitHub account, or your commits will not show up on your profile.

3. fatal: bad object refs/remotes/origin/main

After the config problem, git fetch failed with this. A saved reference to the remote branch was broken.

Fix: delete that reference and fetch again:

git update-ref -d refs/remotes/origin/main git fetch origin 

4. Your branch is based on 'origin/main', but the upstream is gone

This message means your local branch lost the link to the remote branch.

Fix:

git branch --set-upstream-to=origin/main main 

5. ! [rejected] main -> main (fetch first)

My push was refused because GitHub had a commit that I did not have locally. In my case, an automation had committed a file to the repo.

Fix: bring that commit in first, then push:

git pull --rebase origin main git push origin main 

Do not use git push --force to get past this. It can erase someone else's work, or your own.

6. Failed to connect to github.com:443

This one was not a Git problem at all. My computer simply could not reach GitHub.

Fix: open github.com in a browser. If it does not load, check your Wi-Fi, try a phone hotspot, and turn a VPN off or on. Then run the push again. Your commit is safe in the meantime.

7. My images worked locally but not on the live site

My site showed the alt text instead of the images after I deployed. The code was fine. The image files had never been pushed.

git status showed it:

Untracked files: public/skills-web.jpg public/skills-social.jpg 

Fix:

git add public/skills-web.jpg public/skills-social.jpg git commit -m "add skill card images" git push origin main 

Also remember: if you run git push and see Everything up-to-date, it means there is no new commit to push. You may have forgotten to commit.

A harmless warning

You will often see:

warning: LF will be replaced by CRLF the next time Git touches it 

On Windows this is normal and can be ignored.

My safe routine

  1. git status to see what changed
  2. git add <specific files>, not git add ., so I don't commit things like .env
  3. git commit -m "clear message"
  4. git pull --rebase origin main, only if the push is rejected
  5. git push origin main
  6. Open GitHub and check the latest commit

Wrapping up

Almost every error looked scary, and almost every one had a small fix. Read the message slowly. It often says exactly what to do.

You can see my work at ritika-rajput-portfolio.vercel.app and on GitHub.

Which Git error confused you the most when you started?