Exclude some files from inter-branch merges in git

Solution 1:

An alternative approach is to:

  • not track pom.xml
  • track pom.xml.master and pom.xml.mybranch: that way, any merge won't affect them, since they are named differently.

Then, you can version and track:

  • one pom.xml per branch (with a naming convention following said branch).
  • a script able to take the right pom.xml.<abranch> file depending on the current branch, and generate the pom.xml file (which remains untracked, private)
  • a .gitignore which ignores the resulting generated pom.xml file
  • a .gitattribute declaring a smudge content filter (see below)

The generation of the actual pom.xml is automated through a content filter driver, using a .gitattributes declaration.

https://i.stack.imgur.com/tumAc.png
(image from "Customizing Git - Git Attributes" from "Pro Git book"))

Once you declare that content filer driver in your local config, it will automatically, on git checkout, generate your pom.xml file for you.
See a complete example in "Best practice - Git + Build automation - Keeping configs separate".

Repeat the same idea for the appengine-web.xml file.