Always keep your copy of a particular file in a git merge

I found this little gem about how to always keep a particular file untouched during merges. I can think of multiple reasons that you might want to have the same named file in multiple branches of the same repo, while each branch has it’s own unique copy of that file. For me, I have a file in a couple branches that I need to have unique information in it that doesn’t apply to the other branches. This feature allows me to have a unique in each branch.

    git config '"always keep ours" merge driver'
    git config merge.ours.driver 'touch %A'
    echo " merge=ours" >> .gitattributes
    git add .gitattributes
    git commit -m "keep my copy of the file"

Now, when I do a ‘git merge’, I don’t have to worry about my file getting clobbered.


comments powered by Disqus