The idea would be to not version package.json
(keep it private), but to generate it (with the right value in it).
The generation script will determine the name of the checked out branch with:
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
That means you could:
- version only a template file
package.json.tpl
- version value files named after the branches:
version.dev
, version.master
: since they are different, there is no merge issue when merging or switching branches.
Finally, you would register (in a .gitattributes
declaration) a content filter driver.
(image from "Customizing Git - Git Attributes", from "Pro Git book")
The smudge
script, associated to the template file (package.json.tpl
), would generate (automatically, on git checkout
) the actual package.json
file by looking values in the right version.<branch>
value file.
The generated actual package.json
file remains ignored (by the .gitignore
).
See a complete example at "git smudge/clean filter between branches".