When working on a large codebase or a codebase with many developers working on new features, there may come a time when you want to merge specific files from a branch rather than a whole commit or all the changes on the branch. Thankfully, this is easy to do!
Merge specific files
To merge specific files from a branch, use git checkout branch-name file-name. For example:
To break this down, we're merging src/somefile.js and somefile2.js from develop branch and merging it into our current active branch. So, as you can see, this is both simple and powerful!
How is this different from cherry-pick?
Cherry-picking from a branch is different in that this merges specific files only, whereas cherry-picking merges a specific commit and the changes associated with that commit.
To cherry-pick from a branch, use git cherry-pick e26ad04 where e26ad04 is your commit ID.
In general, I would recommend cherry-picking your commits or attempt a standard merge, but if you require a bit more granular control, then it's possible, and simple, to merge specific files into a branch using git.