Towards AI

The leading AI community and content platform focused on making AI accessible to all. Check out our new course platform: https://academy.towardsai.net/courses/beginner-to-advanced-llm-dev

Follow publication

Git Rebase, Merge, Stash, Revert and Reset

Muttineni Sai Rohith
Towards AI
Published in
5 min readDec 24, 2022

--

Git rebase is an advanced feature in git which helps us when we are dealing with multiple branches. Rebasing is a bit more advanced, but incredibly useful when you need it. When you perform a rebase, you are changing the base of your branch. In essence, a rebase will look at each commit on your branch and update the code to make it seem like you’ve been working off the new base all along. Although they have similar uses, a rebase differs from a merge in that a rebase updates your branch by tweaking each commit, and a merge will update your branch by creating a new commit at the tip of your branch.

This is the third addition to the series of articles about Git —
Complete Git Tutorial for Beginners with Examples. The link is available below —

The second article is All About Git Branches… And Git pull vs fetch…
Link Below —

So coming back to understanding Git Rebase, let’s start from scratch and develop the new code in git. Let’s create branch1 and add some new code to it.

git checkout -b branch1

Here we are adding add function in the code -

def add(a,b):
return a+b

a,b = 5,6
print(add(a,b))

Now let’s push the code to our branch1

git add .
git commit -m “adding calculator1 code”
git push origin branch1

Now let’s suppose another developer(developer2) is working on this code by creating branch2 based on branch1 and changing the features while you are working on implementing more functionalities in branch1

Suppose developer2 adds two commits to the code by adding the input() function and adding offset +5 to the add function in branch2

And at the same time, you add two commits sub() function and mul() function in your branch1

--

--

Published in Towards AI

The leading AI community and content platform focused on making AI accessible to all. Check out our new course platform: https://academy.towardsai.net/courses/beginner-to-advanced-llm-dev

Written by Muttineni Sai Rohith

Senior Data Engineer with experience in Python, Pyspark and SQL! Reach me at sairohith.muttineni@gmail.com

No responses yet