Branching & Merging,  Git

merge particular files in another branch

Every now and then I am faced with the question of how I can transfer individual files from a feature branch.

git cherry-pick is intended for taking over the contents of a commit. But if I only want to take over individual files, this tool is probably not the solution.

In order not to make it too exciting, here is the simple answer:

git checkout source_branch <filepath> ...

I want to explain it using a specific example. In the feature branch

426-great-new-feature

I have the files iWwantThat.yml and alsoNeeded2.py. To transfer these two files and only these to the main branch, I switch to the main branch and run the git checkout:

git checkout main

git checkout 426-tolles-neues-feature iWantThat.yml alsoNeeded2.py

Leave a Reply