Common Problems
Don’t worry, nearly everyone runs into these at some point. Here’s how you can fix the most common issues with Git/Github.
”I have merge conflicts!”
Section titled “”I have merge conflicts!””A merge conflict means you’ve changed the same part of a file that has also changed on main since you created the branch. Git doesn’t know which version to keep, so it asks you to decide.
You’ll see something like this in the file:
<<<<<<< HEADscore += 10;=======score += 15;>>>>>>> sam/update-scoreTo fix it:
- Open the conflicting file in your editor
- Decide which version is correct (or combine them if both changes should exist)
- Delete the conflict markers (
<<<<<<<,=======,>>>>>>>) - Save the file, then run:
git add .git commit -m "Merge main into sam/update-score"”I accidentally committed to main!”
Section titled “”I accidentally committed to main!””Don’t push (you shouldn’t be able to anyway). Run this to move your work to a new branch and restore main:
git checkout -b your-name/what-you-were-doing # move your work to a proper branchgit checkout main
# reset main back to the online version (safe to run since you haven't pushed)git reset --hard origin/mainThis works even if you made several commits to main; they’ll all land on the new branch. From there, commit any remaining changes and open a PR as you normally would.
”git push is being rejected”
Section titled “”git push is being rejected””This usually means the online version of your branch is ahead of your local copy. Try:
git pull --rebasegit pushIf you’re pushing for the first time and it’s rejected, make sure you’re using the right branch name:
git push origin your-name/feature-name“I want to undo my last commit (but keep my changes)”
Section titled ““I want to undo my last commit (but keep my changes)””This un-commits your last commit while leaving your files untouched:
git reset --soft HEAD~1“I want to throw away all my changes and start fresh”
Section titled ““I want to throw away all my changes and start fresh””git checkout maingit reset --hard origin/main”I don’t know what state my repo is in”
Section titled “”I don’t know what state my repo is in””These commands help you get your bearings:
git status # see what files have changedgit log --oneline # see recent commit historygit branch # see what branch you're onSomething else is wrong
Section titled “Something else is wrong”If you’re stuck and none of the above tips help:
- Don’t force-push or delete anything, that could make it worse
- Screenshot or copy the error message
- Ask a club leader, they’ve might’ve seen it before