In my project, I have this constants.ts
file which stores my API_URL
.
The idea would be to store two files:
constants.ts.main
constants.ts.dev
(I use main
instead of master
here)
- keep
constants.ts
ignored from now on: echo constants.ts>>.gitignore
.
That means generating the right constants.ts
file locally: no complex merge involved when merging dev
to main
.
In each branch, you would then generate constants.ts
, with the right content in it, from one of those files, depending on the current execution environment.
The generation script will determine the name of the checked out branch with:
branch=$(git rev-parse --symbolic --abbrev-ref HEAD)
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 the constants.ts
file, would generate (automatically, on git checkout
or git switch
) the actual constants.ts
file by looking values in the right constants.ts.<branch>
value file.
The generated actual constants.ts
file remains ignored (by the .gitignore
).
See a complete example at "git smudge/clean filter between branches".