DEV Community

Fernando Tricas García
Fernando Tricas García

Posted on

So, you want to merge just some changes from another git branch?

I'm working on a separate development branch but I've discovered that, maybe, some changes could be integrated in the main branch (but not all of them). What can I do?
There are several solutions in How can I selectively merge or pick changes from another branch in Git?, but I've found easy to follow and convenient the following one:

"Let’s say you have the master, exp1, and exp2 branches. You want to merge one file from each of the experimental branches into master. "

git checkout master 
git checkout exp1 path/to/file_a
git checkout exp2 path/to/file_b

# Save these files as a stash
git stash

# Merge stash with master
git merge stash
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay