Member-only story
Git Rebase, Merge, Stash, Revert and Reset
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