DEV Community

Andrew Lee
Andrew Lee

Posted on

My Git Rebase Workflow

This is my workflow when contributing to code. First I create a branch to implement a specific feature:

git checkout -b some-feature
Enter fullscreen mode Exit fullscreen mode

Once I make changes, I commit and push:

git add .
git commit -m "Some changes"
git push -u origin some-feature
Enter fullscreen mode Exit fullscreen mode

Sometimes, I need to update my branch with changes that happened on master. To get the latest changes on master and replay my changes on top, I run the following command:

git pull origin master --rebase
Enter fullscreen mode Exit fullscreen mode

There are pros and cons of rebasing master instead of merging master. We will have a cleaner commit history (no merge commits) with rebasing. However, some claim that merges are better because it does not rewrite history like a rebase.

When we try to push after rebasing, we'll get a warning since the local branch's history has been changed. While its dangerous to do so on the master branch, we can just force push our changes to our feature branch.

git push origin some-feature --force
Enter fullscreen mode Exit fullscreen mode

I prefer rebasing over merging for two main reasons. First, I can have clean commit messages. Second, it's easy for me to visualize in my head: rebasing is just putting my changes after all of the latest changes on master.

Top comments (1)

Collapse
 
vishnubaliga profile image
Vishnu Baliga

Good one! :)