Git Merge vs Git Rebase

TLDR

Both git rebase and git merge are used to synchronise changes between branches. The difference is git rebase will revise the commits but keep a clean organised history, while git merge will keep all the original commits and add ones automatically but gives out a circuit board like history.

Real world scenarios

Image you have two branches: feature and master. feature is from master, after some time, for some reason, master has some changes which feature doesn't have

Git merge

What git merge do:

  • Wouldn’t change the commit timestamp
  • Wouldn’t change the commit hash
  • Will create a new commit automatically
  • When there are many people are using the git merge in a project, it will cause commits across each other in history, in the end it will show the commits like a Circuit board.

How to do git merge:

  • Step 1: git checkout feature
  • Step 2: git merge master , might need to resolve some conflicts while doing this step

Git Rebase

What git rebase do:

  • Change the commit timestamp
  • Change the commit hash
  • Not introduce any new commit automatically
  • Generate nice and organised git history, like the one in the following:

git rebase will move the current changes to upmost, and keep the current change history.

How to do git rebase:

  • Step 1: git checkout feature
  • Step 2: git rebase master , might need to resolve some conflicts while doing this step. Here we might rebase the code multiple times. So it is a good idea to squash all the commits into one.

Reference

https://www.atlassian.com/git/tutorials/merging-vs-rebasing

Originally published at https://needone.app on January 12, 2021.

--

--

--

needone.app

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Customizing Ubuntu 18.04

EE5111 IoT Project on Amazon AWS

How Mockito Works?

How to implement expandable menu on iOS (like in Airbnb)

Count BST nodes that lie in a given range

Managing Agile DevOps with CAKE

III: C in Real Time

Cloud Secuat the Speed of Serverless

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Needone App

Needone App

needone.app

More from Medium

Setting up JAVA_HOME on MacOS

Git Workflow Comparison

Git rebase local branch

Should I cache my Queries?