What is git rebase and how to use it
Git rebase is used to synchronize your current bramch with the target-branch / created-branch / any-branch
In current branch, the commits comming from target-branch will be kept below the commits done in the current branch.
Pros:
- Used to reduce one merge commit and have cleaner commit history
Example
Lets create a branch called feature-1
from dev
branch and do two commits in feature-1
branch
Go to dev
branch and do two commits there
Now go to feature-1
branch and run rebase command to bring dev
commits below the commits in feature-1
branch
git rebase dev
If you are pushing the feature-1
branch for first time then no issue, simple git push origin feature-1
should work
If you have already pushed feature-1
branch with some commits and now if you are trying to push it may fail, since we have altered the commit history, we have the push the branch forcefully
git push origin feature-1 -f
Note: You should use git rebase very carefully, since it alters the commit history