Git: Pull, Merge, and Rebase - What's the Difference?

You might have used git merge, pull, and rebase in Git.

Ever wonder what's the difference?

Let's break these down into simple terms:

What is Merge?

Using git merge is creates a commit combining two branches. If there are conflicts, Git will ask you which version to keep. After you decide, your branches are combined, and a commit message is added that shows you have joined two branches.

This can be fantastic because you can see as a commit when branches were joined together (and any issues it may have caused).

What is Pull?

Think of git pull as effectively running git fetch and git merge. So when you pull, you're doing two things: first, checking to see what's new (git fetch), and then adding those updates to your project (git merge). This adds these changes as a commit to your branch.

What is Rebase?

git rebase is like redoing your work over someone else's. Rebase takes the latest changes (if any) and then adds your changes on top of them. This makes the project commits look cleaner because everything was done in a straight line, one after the other. You don't have the commit message like when using merge or pull. It does, however, become more complex when you hit conflicts.

This is often a favorite of projects to keep the commit history looking cleaner rather than having all of the merge commits added.

The TLDR;

  • Merge combines two branches, deciding how to mix overlapping parts.
  • Pull is like merge except it checks for changes first.
  • Rebase is making your work follow someone else's, making the project history look cleaner but more complex to handle.
Git
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.

Loading

Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.