How to prevent merging of excluded files?

Let’s say I have file secret_config in .git/info/exclude. My colleague, who doesn’t know about this file, thinks file with such name might look shiny in his repository, so he creates, commits and pushes it. I, in good mood, want to pull, as every morning, but git starts to yell at me:

error: Untracked working tree file ‘secret_config’ would be
overwritten by merge. Aborting

  • Git rebase master and multiple branches
  • How to set up a git project to use an external repo submodule?
  • Files are listed as modified directly after clone
  • In Git, how do I get a detailed list of file changes from one revision to another?
  • How to setup PC and Mac for using git
  • Git rebase -i not in terminal / only works with sudo
  • How to tell git to stop yelling at me? Is it possible to tell him to completely ignore this file even while pulling or fetching/merging?


    When I temporarily create .gitignore and put secret_config to it, it, at least, allows me to pull properly. I need to emulate this functionality somehow.

  • check detailed file list to push in git
  • I can’t get `git tag -s` to ask for my GPG password
  • git commit frequency
  • merge branch that was created from old commit to master
  • Git: delete a single remote revision
  • Generate a version number of my site thanks to git?
  • 2 Solutions collect form web for “How to prevent merging of excluded files?”

    You can share your list of ignored files via .gitignore, e.g.

    $ mv .git/info/exclude .gitignore
    $ git add .gitignore
    $ git commit -v "Add ignored file list"
    $ git push

    Next time he pulls he will inherit your list of ignored files. This doesn’t fix the history of files he already committed in his repository though.

    It’s not exactly a solution, but there’s possibility to change merging strategy, so file always keeps your local version. You just need to create file .gitattributes in the same directory as file you want to prevent merging and put name_of_file merge=ours in it. Downside is, you have to commit this file, so it feels like polluting repository with junk that no one but you needs.

    Git Baby is a git and github fan, let's start git clone.