Applying patches with modifications from other branch

Normally we create a new branch on git to test a new code and when it is working fine we want to move it again to master. There are many ways to do it.

Today my friend Daniel found a nice way to do it:

git diff master mytestbranch | git apply --index -

It will move all modified files from “mytestbranch” to “master” branch.

If you want to move just a specific directory or file, you can follow the command by “– “, example:

git diff master mytestbranch -- src/ | git apply --index -

In this case I just want the modifications which affect the src/ directory.