World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

Push rejected? Fix it

You will learn: why GitHub sometimes refuses your push, and the calm fix.

The problem

Your teal titles are ready. Tap Push. Watch what comes back.

Your laptop~/diary
  1. c1240a3Make titles teal (only on your laptop)main (HEAD is here)
  2. ea2c020Add purple styleorigin/main
  3. f6c78e5Add home page
  4. 2efd0f2Add README
1 ahead · 0 behind origin/main
GitHubgithub.com/you/diary
  1. c64aa8eAdd Aisyah's day 2 · Aisyah (only on GitHub)main
  2. ea2c020Add purple style
  3. f6c78e5Add home page
  4. 2efd0f2Add README

Tap an action. Watch the courier.

Watch

GitHub has Aisyah’s new commit. Yours doesn’t build on it. So GitHub says no, to keep her work safe. Tap the line that refuses, and the line with the fix.

Tap the refusal and the fix.

0 of 2 found

Try it

Fix it with the courier. Bring Aisyah’s commit down, then push again.

Your laptop~/diary
  1. c1240a3Make titles teal (only on your laptop)main (HEAD is here)
  2. ea2c020Add purple styleorigin/main
  3. f6c78e5Add home page
  4. 2efd0f2Add README
1 ahead · 0 behind origin/main
GitHubgithub.com/you/diary
  1. c64aa8eAdd Aisyah's day 2 · Aisyah (only on GitHub)main
  2. ea2c020Add purple style
  3. f6c78e5Add home page
  4. 2efd0f2Add README

Tap an action. Watch the courier.

Predict

A friend says, “Just add --force!” What happens to Aisyah’s commit on GitHub?

Pick one answer.

Check

Push rejected? Put the calm fix in order.

First step at the top. Put these in order. Use the arrows, or drag.

  • Push, and it gets rejected
  • Fix conflicts, if Git asks
  • Pull to bring in the new commits
  • Push again

Try it

Now in the terminal. Push, read Git’s words, fix it, push again.

2efd0f2f6c78e5ea2c020c1240a3

You did it!

You can now fix a rejected push without losing anyone’s work.

Go deeper (optional)

Fetched already, but not pulled? Then Git says “non-fast-forward” instead of “fetch first”. Same fix: pull, then push. A push can also be refused by branch rules on GitHub. That is World 5.