DEV Community

How to Fix a Typo After You've Already Pushed Your Commit

Bella Woo on February 07, 2020

Or alternative title - How I learned to love Git rebase When I first started working with Git, I was indoctrinated into the school of me...
Collapse
 
jdforsythe profile image
Jeremy Forsythe • Edited

Your alternative title is better. You should never rebase after you push to a remote. Ever.

Collapse
 
kiliman profile image
Kiliman

I would clarify that as never rebase after you push to a remote shared with others. I push and rebase my feature branch all the time. It's especially helpful when reviewing pull requests.

Collapse
 
bellawoo profile image
Bella Woo • Edited

A feature branch pushed up to a shared repository is available to others, so at this point, it becomes a matter of communication and etiquette. I wouldn't force push to a remote branch if someone else is actively committing or has an upstream based off of mine, but that situation is rare on the teams I work on.

Thread Thread
 
kiliman profile image
Kiliman

If we end up with a feature branch that other developers would work on (pretty rare), we would just treat it like we do for master. Create a new branch off it, rebase and merge. Same workflow.

Thread Thread
 
jdforsythe profile image
Jeremy Forsythe • Edited

While it may be rare, I prefer a workflow that doesn't have any gotchas. If we never rebase anything that has been pushed, our workflow never requires the developer to wonder if anyone else might be affected by a rebase. My devs have enough to think about. The more I can take off their plate, the better.

Thread Thread
 
kiliman profile image
Kiliman

That's the nice thing about git. It supports different workflows. So whatever works best for your team is what you should do. There is no right or wrong way.

Collapse
 
itsjuuulio profile image
Julio

As someone who makes many typos for a living, these are great!!

Collapse
 
aminarria profile image
Amin Arria

Really great of fixing multiple mistakes along the history.

One question, if it's just the latest commit you need to fix why not use git commit --amend?

Collapse
 
bellawoo profile image
Bella Woo

I often like to fixup and then keep going with my work. Then I'll rebase when I feel that I'm at a natural stopping point. But git commit --amend is an option!

Collapse
 
codefinity profile image
Manav Misra

😳 That’s a lotta work to fix a sepling error! Good for you, though. This level of attention to detail implies that you are a polished developer.

Collapse
 
bellawoo profile image
Bella Woo

Thanks! It's not only typos. Sometimes I may commit a "WIP", but fixup or squash the commit ass I get closer to opening a pull request. Getting comfortable with this technique has taught me the value of presenting polished work, to borrow your description. :)