If you are a software engineer working in a team, then you are probably using git for version control. Imagine working on a certain feature and when your branch is merged to the base branch, everything breaks down because after you checked out from the base branch some changes were pushed to it. Well, there is a basic workflow that can help you avoid all that and make your life easy. This post will take a shallow dive into the process of git rebasing
.
What is git rebase
Consider a situation where your teammates have made some changes to the master branch since you started working on your feature branch. So you want to get the latest changes so it seems like you have been working on the latest branch. Rebasing gives you the opportunity to merge the master branch with your feature branch while still maintaining a clean history.
Let's get to it
I use the following process on a daily basis to get the latest changes from the development branch and resolve conflict.
Key:
- feature-branch - The branch you are working on.
- base-branch - branch you want to merge to.
When you are on your current working branch,
Method one:
- $ git checkout base-branch
- $ git pull origin base-branch
- $ git checkout feature_branch
- $ git rebase base-branch
Method two:
- $ git pull --rebase origin base-branch
Resolve any conflicts you may have
- $ git add .
- $ git rebase --continue
- $ git push origin branch-name -f
Conclusion
As you can see, git rebase is quite an easy process that you can complete in less than a second😃. In just a few simple commands and you have all the latest changes. Stay frosty by using awesome git workflow techniques.
Top comments (1)
Nice read...now to make sure my team knows of this awesome technique