Clean up your crime scene of a pull request

Reece Boyd
Soluto Nashville
Published in
2 min readApr 7, 2020

--

A few git commands to help you get away with the murder of your codebase

“There was a struggle”

Congrats on getting your code to work! But you’re not done yet. Developers of today will drop what they are working on to review your code. Developers of tomorrow will review your code to understand how something works. Here are simple steps to clean up your code and make it painless for your victims — I mean peers:

Are your commits like a crime scene? Do they reveal a struggle between you and the code?

git fetch && git reset —-soft origin/master

will take all of your commits that are different than what we would presumably have running in PROD and move them back to staging.

If you have been doing a lot of trial and error, do and undo type commits, this can be a one command cleanup. Just recommit 1 pretty commit that looks like you didn’t even struggle.

Is your PR doing too much? (Apply the Single-Responsibility Principle to PRs)

The previous command can also be useful if you decide your PR accomplishes 3 things and should therefore be 3 PRs instead of 1. Now that your changes are back in staging, you can easily make 3 neat commits and cherry-pick these commits out to their own branch, like so:

git checkout -b branch-for-commit-1git cherry-pick <commit SHA for commit 1>git push #push that branch up to origin so you can make a PR

Repeat for commits 2 and 3.

Different crimes, different measures:

Want to combine the last 2 or 3 commits instead of ALL of the differences between your branch and master?

git fetch && git reset —-soft HEAD~2 # or 3 or w/e # you want

--

--

Reece Boyd
Soluto Nashville

Coding & Financial Independence | Follow me on Twitter @reecealanboyd https://twitter.com/reecealanboyd