With Git, sometimes you need merge between branches. For example, you need merge BranchB to BranchA. Almost cases, if it has conflicts, you will open the conflict file and merge it manually. But in some cases, you have to keep file at either BranchA or BranchB. Fortunatly, “git checkout” command with options will help you do that.
To merge between 2 local branches:
1 2 |
git checkout BranchA git merge BranchB |
Or merge a remote branch to a local branch:
1 2 |
git checkout BranchA git pull origin BranchB |
To keep the file that we own:
1 |
git checkout --ours [file_name] |
To keep the file that they own:
1 |
git checkout --theirs [file_name] |
In case you have too many files conflicted, you can use the command below:
1 |
for f in `git ls-files -m`;do git checkout --ours $f; done; |