how to maintain a production and development branches in git?
Asked Answered
N

1

2

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?

Napiform answered 9/6, 2021 at 5:15 Comment(0)
M
2

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.

smudge (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".

Mordant answered 9/6, 2021 at 6:9 Comment(1)
this is really awesome Thank you!Napiform

© 2022 - 2024 — McMap. All rights reserved.