git workflow: Can I prevent a certain file from being merged to another branch but still keep it under version control?

I found an answer on another question on Stack Overflow, credit goes to fcurella:

Let’s say you want to exclude the file config.php

On branch A:

  1. Create a file named .gitattributes in the same dir, with this line: config.php merge=ours. This tells git what strategy to use when merging the file. In this case it always keep your version, ie. the version on the branch you are merging into.

  2. Add the .gitattributes file and commit

On branch B: repeat steps 1-2

Try merging now. Your file should be left untouched.

This seems like a more scalable solution.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)