Git & Github - Common Issues
Common Problems:
Local vs Remote Histories
Sometimes GitHub already has commits (like an auto-generated README) while your local project has its own commits.
When you try to push, you may see:
![rejected] main -> main (non-fast-forward)
error: failed to push some refs to https://github.com/somegithub/somerepository
This means your local and remote histories diverged..
Notice that the divergion happened at 'B'.. meaning that the top row is ahead by 'C'
If this happens then:
Why this happens:
Your local branch and the remote branch have different commits.
Git refuses to overwrite history unless you merge them.
First fetch and allow for unrelated histories:
git pull origin main --allow-unrelated-histories
- Resolve any conflicts (e.g., in
README.md). - Stage and commit the resolution:
git add . git commit -m "some-commit-message-here" - Push again:
git push origin main
Now what?
YOU DID IT!
Practice creating a repo, adding files, committing, and pushing to GitHub.
Next step: learn branches and pull requests for teamwork!
Common Issues
Beginner Git Problems
- “I committed to the wrong branch”
- Forgetting to create/switch to a feature branch before working.
- Fix: use
git checkout -bearly, orgit switch -c.
- “I deleted files accidentally and Git removed them”
- Git tracks deletes as well.
- Fix: restore with
git checkout -- filenameorgit restore filename.
- “My files are ignored / not showing up”
- Usually caused by
.gitignorecatching them.
- Usually caused by
- Merge conflicts
- Happens when two people change the same line in a file.
- Fix: manually edit, then
git addandgit commit.
- “Detached HEAD state”
- Happens when you checkout a specific commit instead of a branch.
- Fix: create a new branch from that commit.
Intermediate Git Problems
- “Accidentally pushed secrets” (API keys, passwords)
- Removing them isn’t just deleting — you may need to rewrite history (
git filter-repo) or rotate keys.
- Removing them isn’t just deleting — you may need to rewrite history (
- “I want to undo my last commit”
git reset --soft HEAD~1(keep changes staged)git reset --hard HEAD~1(discard changes)
- Force push mistakes
- Overwriting remote history by accident (
git push --force). - Can wipe out teammates’ work.
- Overwriting remote history by accident (
- Cloning into the wrong folder
- Ending up with nested repos (
myrepo/myrepo).
- Ending up with nested repos (
- “I can’t pull because I have local changes”
- Fix: commit or stash before pulling.
Remote / GitHub Problems
- Different local vs remote histories (your exact case)
- Non-fast-forward errors, diverged timelines.
- Forgot to set upstream branch
- First push fails → need
git push -u origin main.
- First push fails → need
- Permission denied (publickey)
- SSH key not set up properly.
- Repository not found / 403 error
- Wrong URL or missing permissions.
- Large file rejection
- GitHub blocks files >100MB. Needs Git LFS or different approach.
Git & GitHub - Documentation
Finished
Back to Overview: Developer Fundamentals

