Sharing Your Git Patches

Another way of sharing quick suggestions with your team

Image for post
Image for post

Imagine this situation

You are reviewing a Pull Request (PR) and you see some minor improvements or suggestions that you would like to share with the author. You might write some comments, and usually, that would be sufficient.

What possibilities are there apart from just comments in a PR?

Well, there are multiple options. The key is to be aware of them and use them wisely depending on the priority of the task and the changes themselves:

  • We can always do some pair-thinking, talk at any time. Communication is always good in order to clarify the possible uncertainty.
  • Sharing your git patches is another good option.

Git diff to the rescue!

What if you (as a reviewer) could share your idea without any single commit or comment in the PR, but sharing your changes directly with the author?

git diff origin develop > ../my-origin-develop.patch

What we are doing here is redirecting the output of the diff command into a file (aka: patch), so we can share that output with any other peer-team.

What now?

Well, having that patch file, it’s pretty easy to apply those changes in your local machine without doing any commit on its own:

git apply ../my-origin-develop.patch

Applying this patch will simply change your local system in the same way the patch was created, without any unexpected commit; No worries about that!

“How to” by steps

Let’s divide the responsibilities into two: the creator of the patch and its user:

The patch creator: the person who will create the patch

# Checkout that branch
$ ~/myProject git:(the-branch) ➜ git pull origin the-branch
# Do your suggestions and changes in the targeted branch# Generate the patch file using the diff command
$ ~/myProject git:(the-branch) ➜ git diff > ../your-diff.patch
# Share the patch file with the author of the PR

The patch user: the person who will see the patch

# Ensure you are in that branch
$ ~/myProject git:(the-branch) ➜ git pull origin the-branch
# Apply the patch file
$ ~/myProject git:(the-branch) ➜ git apply ../your-diff.patch
Image for post
Image for post

The Startup

Medium's largest active publication, followed by +756K people. Follow to join our community.

Thanks to Francisco Marín

Jose Maria Valera Reales

Written by

Aka: Chema. I love what I do: software, music, and sport, but here I write mostly about software.

The Startup

Medium's largest active publication, followed by +756K people. Follow to join our community.

Jose Maria Valera Reales

Written by

Aka: Chema. I love what I do: software, music, and sport, but here I write mostly about software.

The Startup

Medium's largest active publication, followed by +756K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store