DEV Community

Discussion on: Git merge specific file from another branch

Collapse
 
marvinkweyu profile image
Marvin

What this does is replace a file on a branch with the file from the other branch.The actual solution would look like this:

Say I had a file1.txt in branch B I wanted to merge with a file1.txt in branch A.

git checkout A

git checkout --patch B file1.txt
Enter fullscreen mode Exit fullscreen mode

1.First, get yourself to branch A(Where you want to do the merge).
2.Patch with the file from branch B.

If your file1.txt does not exist in branch A , leave out the option --patch.
Note that once this command is run, you can accept options that will be provided in the terminal. You can choose to accept with the y or regect with n and so on

Collapse
 
m3ck0 profile image
Giorgi Jambazishvili

Thanks, this saved my googling time :)

Collapse
 
marvinkweyu profile image
Marvin

Glad I could help

Collapse
 
himito profile image
Jaime Arias Almeida

Thanks a lot !