World map

 

BM: Baca dalam Bahasa Melayu

World 4: Hello GitHub

Pull with merge or rebase

You will learn: what to do when you and GitHub both have new commits.

The problem

You made titles teal. Aisyah pushed her day. Both of you have a new commit. Tap Pull. What does Git say?

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

git pull --no-rebase makes a merge commit. Your commit and Aisyah's commit both lead into it, like the letter Y.
2efd0f2f6c78e5ea2c020c1240a3

git pull --no-rebase joins the two with a merge commit. History keeps both paths, like the letter Y.

Predict

Which pull gives one straight line of history?

Pick one answer.

Watch

git pull --rebase lifts your teal commit and puts it on top of Aisyah's commit. The history is one straight line.
2efd0f2f6c78e5ea2c020c1240a3

git pull --rebase lifts your commit and puts it on top of Aisyah’s. One straight line. Your commit gets a new hash, because it has a new parent.

Try it

Tired of choosing every time? Build the command that makes rebase your usual way.

Tap the pieces in the right order.

…

Try it

Pull Aisyah’s commit your way. Then push both commits.

2efd0f2f6c78e5ea2c020c1240a3

Check

Good habit, or needs work? Swipe each one.

Swipe right for good, left for needs work. Or use the buttons.

1 / 4

Rebase your own commits that you have not pushed yet

Rebase your own commits that you have not pushed yet

You did it!

You can now pull with merge or rebase, and pick your way.

Go deeper (optional)

git config --global pull.ff only makes pull refuse anything but a fast-forward. A rebase can stop on a conflict, like a merge. Fix the file, git add it, then git rebase --continue. Or run git rebase --abort to go back.