Make Clean Pull Requests — version control and collaboration

Written by asantos3026 | Published 2017/08/11
Tech Story Tags: git | collaboration | clean-pull-requests | pull-request | version-control

TLDRvia the TL;DR App

This is the first installment of the technical portion of my blog for junior developers. I come from a non-traditional coding background so I work hard and practice the ABC’s (Always Be Coding). Half of my blogs will be about technical subjects and the other half will be about equality, social justice, and tech for good.

For the past couple of weeks, I have begun my journey in Software Engineering. One of the most challenging, out of the MANY, things to learn has been version control. You want to make sure that your pull requests are clean so that code reviewers can efficiently comb through your code and give you feedback that will help increase its quality, performance, and readability.

Picture this scenario, you finish working on your feature branch. You feel proud and ready to rule the world with your awesome code. You go through your normal git flow and realize you have brought on to your branch all of the other commits and file changes associated with this feature since the beginning of time. Now you have umpteenth files and thousands of commits included in your pull request.

If you’re new to development in large teams or a large codebase, then this exact situation may have happened to you. After eating this frustrato chip a few times, I sat down at home and walked through the git process to make sure I knew exactly how to create clean pull requests each and every time.

Here are the steps to creating a copy of your branch and cherry picking the commits to be included to ensure only those files and commits will be added to your PR.

Steps:

  1. Cut a new branch off of your upstream git checkout -b <new-branch-to-copy-feature-on>

  2. Rebase and squash all commits to one. `git rebase -i HEAD~<number of commits from last> or git rebase -i upstream/<repo-you-forked-from>

  3. Edit your commits and write a descriptive commit that shows the overall story of your PR

    pick #Clear commit message that tells the full story of my featurefixup #Commit Message 2fixup #Commit Message 3 //fixup allows you to squash your commit and not include the message

4. Check your log and make sure you only have one commit `git log

5. Perform a hard reset on your upstream to make sure you have the latest.

`git reset --hard upstream/<my-upstream>

6. Cherry pick your commit into your new branch

`git cherry-pick <your-one-commit-number>

7. Fix any merge conflicts and choose the latest changes after the HEAD section

8. Add your changes, commit and continue

git add -pgit commit -m "My Shiny New Branch With My Only Commits"git cherry-pick --continue

9. Add your changes to your new branch

git push origin <new branch>:<old branch> -f

10. Go to your PR link, sit back, and enjoy the fact that you made your fellow devs’ lives easier

Oh yeah!


Published by HackerNoon on 2017/08/11