How to Share Git Changes Without Committing Using Patch Files

Follow on LinkedIn

When working in a team, you might need to share uncommitted changes with a teammate without making a commit. Git allows you to export staged changes into a patch file, which can be applied later by another developer. This is useful when you want to share updates without modifying the commit history.

In this article, we’ll cover:

  • Creating a patch file
  • Sharing the patch with teammates
  • Applying the patch

Step 1: Create a Patch File

First, ensure you have staged the changes you want to share:

git add file1.txt file2.js

Then, generate a patch file:

git diff --staged --binary > my_changes.patc
  • --staged ensures only staged changes are included.
  • --binary allows binary files (like images) to be stored.
  • The output is saved in my_changes.patch.

Step 2: Share the Patch File

Now that you have a patch file, share it via:

  • Email 📧
  • Slack/Teams 💬
  • A file-sharing service like Google Drive or Dropbox 📂

Your teammate can now download and apply it.

Step 3: Apply the Patch

Once your teammate receives my_changes.patch, they can apply it using:

git apply my_changes.patch

This applies the changes to their working directory without creating a commit.

Bonus: Verify Applied Changes

To check the applied changes, run:

git status

If everything looks good, they can continue working or commit the changes:

git commit -m "Applied patch from teammate"

Why Use Patch Files Instead of a Commit?

Avoid unnecessary commits in feature branches.
Share code without pushing to a shared branch.
Great for quick fixes when collaborating.

This method is a simple way to share progress without disrupting the commit history.

Leave a Reply

Your email address will not be published. Required fields are marked *