Reputation: 237
In my project i have this constants.ts
file which stores my API_URL
. I want to keep two API_URLs in my production(main) and development branches.
ex: development -> API_URL = 'http://localhost:4000' main -> APIURL = 'https://backend.com'
but when I change the API_URL and commit when it comes to merging the main and the development branch it detects as a change. so if I merge it constant file in main branch will be also changes. How to ignore the changes of this file?
Upvotes: 2
Views: 817
Reputation: 1323343
In my project, I have this
constants.ts
file which stores myAPI_URL
.
The idea would be to store two files:
constants.ts.main
constants.ts.dev
(I use main
instead of master
here)
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".
Upvotes: 2