DEV Community

Cover image for Git power tool: patch
Mathijs Vogelzang
Mathijs Vogelzang

Posted on

1

Git power tool: patch

Git has many tools that you don't normally encounter in day-to-day use.

One very powerful one I've started using recently is the "patch" flag.

Say you're working on a branch, and you discover you need something you've already implemented on a different branch. Not the whole change, just a tiny bit (in case you want the whole change, git cherry-pick or git merge are more appropriate).

Instead of manual switching and code-copying, you can use git checkout --patch (or git checkout -p for short).

It works like this:
I'm on branch featureA and want to copy things from branch featureB.

I execute:

$ git checkout -p featureB
Enter fullscreen mode Exit fullscreen mode

(If you know which particular file or directory you want to patch, you can also add that as the last argument, like git checkout -p featureB src/my_page.tsx)

I now get walked to all parts of the change (called hunks) and get asked if I want to apply them or not:
Screenshot of patching with git

Very convenient!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)