AI Hints
Home›Git & GitHub Tutorial›Pulling in a Team
Git & GitHub · Lesson 66 of 144

Pull with Rebase

A straight-line history.

⏱ 2 min read▶ Video at 1:11:56🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Every time you pull while both sides have new commits, Git adds a merge commit. In a busy team, history fills up with lots of little merges. There's another option. Pull with rebase.

Pull with Rebase
From the video: Pull with Rebase
  • Lots of tiny merge commits
  • A messy history
  • Another option: rebase

git pull --rebase

Same situation. Alex pushed, and we have a local commit. This time, git pull dash dash rebase. Git takes our commit off, brings in Alex's commit, then replays ours on top. The graph is now a straight line. No merge commit at all.

git
git pull --rebase
From https://github.com/sam/my-site
   f63a17a..7893b97  main       -> origin/main
Successfully rebased and updated refs/heads/main.
git log --oneline --graph -n 3
* c8dce82 (HEAD -> main) Style the footer
* 7893b97 (origin/main) Mention the blog
* f63a17a Link to about page

What rebase did

Here's the picture. Our commit, S, and Alex's commit, A, both started from the same point. Rebase moved S, so it starts after A instead. It's a new copy of S, with a new hash, sitting on top. The result is a simple, straight history.

Merge or rebase when pulling?

Both are fine. Merging keeps the exact history of what happened, including the merges. Rebasing keeps the history clean and straight. Many teams set pull to rebase by default. Whatever your team uses, just be consistent.

git pull (merge)

  • Keeps exact history
  • Adds merge commits

git pull --rebase

  • Straight history
  • Your commits get new hashes

Summary

Git pull dash dash rebase replays your commits on top, for a straight history. Next, a practice round with remotes.

Key takeaways
  • git pull --rebase
  • Replays your commits on top
  • No merge commit
Next up: Practice: Remote Challenges — push, pull, and status