Search code examples
gitgithubbranchgit-mergegit-branch

How to ignore specific files during merging of branches in Git?


I have some environment specific files in a Git repo.

When I merge my dev branch to master, I don't want to overwrite those files in master with the ones from dev.

How can I set those files to be ignored when merging the branches?


Solution

  • Merge and then just check them out:

    git merge some_branch --no-commit -m "some merge"
    git checkout HEAD -- file1 file2 file3
    git merge --continue
    

    You might set GIT_EDITOR to /bin/true if the process is going on in a script:

    GIT_EDITOR=/bin/true git merge --continue