Git rebase is one of the most recently used command if you are using git/githib for your version control.
To pull in from the central repository we use a
git pull --rebase
to rebase current branch to another branch we use
git checkout <branch1>
git rebase <branch2>
But many people don't know what exactly a git rebase is doing. So I thought I wouldn't I write down what I found. So here is an example
So I am in the branch team2 currently , and I want the changes of team1 in the branch team2. What would I do? obviously I would go for a
git rebase team1
What will be the end result?
The git log from team2 would print the below
Holy cow ! how did that happen?? That's what git rebase does , it will go up the hierarchy to find a common parent commit and then apply the changes from the branch to be rebased in this case the team1's commits. Then ontop of that all the commits from the current branch is re applied. So that is how rebasing is done.
To pull in from the central repository we use a
git pull --rebase
to rebase current branch to another branch we use
git checkout <branch1>
git rebase <branch2>
But many people don't know what exactly a git rebase is doing. So I thought I wouldn't I write down what I found. So here is an example
a -> b -> c-> d (master)
| |
| k (team2)
e -> f -> g (team1)
So I am in the branch team2 currently , and I want the changes of team1 in the branch team2. What would I do? obviously I would go for a
git rebase team1
What will be the end result?
The git log from team2 would print the below
a ->e -> f -> g -> b -> c-> d ->k
Holy cow ! how did that happen?? That's what git rebase does , it will go up the hierarchy to find a common parent commit and then apply the changes from the branch to be rebased in this case the team1's commits. Then ontop of that all the commits from the current branch is re applied. So that is how rebasing is done.
No comments:
Post a Comment