Sikau

Git & GitHub · Day 16 · about 30 min

When push is rejected

Someone pushed first: pull, resolve, push.

"Updates were rejected"

You commit, push… and Git refuses: the remote has commits you don't have. Git is protecting your teammate's work from being overwritten. The fix is always the same: pull, (resolve), push.

Pull, then push

echo "Momo: Rs 180" > prices.txt
git add .
git commit -m "Add prices"
git push
git pull
git log --oneline --graph -4
git push
  • If the pull conflicts, resolve exactly as in Unit 2: edit, git add, git commit, then push.
  • Never "fix" a rejected push with git push --force on a shared branch — it deletes your teammate's commits from GitHub.

The rest of this lesson

  • Why Git rejects the pushexplain
  • Force-push: know when, and never on shared branchesexplain
  • Push rejected. Next?predict
  • Rejected pushorder
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 18 lessons of Git & GitHub