I have 2 branches, dev and master. In dev, there is a file that I don't want in master, but I still need to track it. However I cannot get git to ignore this file when merging from dev to master.
I use 2 machines, one where I commit to dev and other where I merge. The sequence I did is the following:
1. Machine 1: Create and push .gitattributes
Create a .gitattributes file with:
path/to/file.py merge=ignore
Commit file:
git add .gitattributes
git commit -m "adding .gitattributes"
git push
2. Machine 2: Merge
git config --global merge.ignore.driver true
git pull
git checkout master
git merge dev
# file is neither in master nor in dev, will e commited in the next step
ls path/to/file.py
# ls: cannot access 'path/to/file.py': No such file or directory
3. Machine 1: Commit the file to be ignored on merge
git add path/to/file.py
git commit -m "adding file.py"
git push
4. Machine 2: despite .gitattributes, git merge does not ignore file.py
git merge dev --no-commit
# file is not ignored and ready to be merged to master...
ls path/to/file.py
# path/to/file.py
What am I doing wrong?
EDIT: This answer was suggested as duplicate. You may see from commands above that I'm doing basically what is suggested in the answers there, but it does not work, so I keep trying to find the solution. Also, Git hooks mentioned in the same place are not portable (repo is used by both Windows and Mac users).