DEV Community

Andrew Lee
Andrew Lee

Posted on

2

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.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (1)

Collapse
 
vishnubaliga profile image
Vishnu Baliga

Good one! :)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs