Home > database >  How to make git skip some files on merge between branches
How to make git skip some files on merge between branches

Time:02-14

I have a docker multi-project, where some files are configuration and bash scripting files

  • .env (eg. facebook_app_id=abcd)
  • build.sh (eg. checkout project with depth 1)
  • install.sh

They specify how the different projects communicate together, which is different when in production or in development mode.

I solved this by creating different branches (dev, test, preprod, and prod) and having those files with the same names but different content in each branch.

So my need is to have those files present in git, but I don't want them to override content between branches. I can have a version in master, then modify it in each branch so that they become conflicting to get a warning at each merge, but that's not very user-friendly.

I've read this post, but it still doesn't answer my needs.

Any ideas?

CodePudding user response:

Since you want the files to be part of your repo, you dont want to ignore them.

But changes to settings for environmental-dependent attributes shall not be commit and merge every time. You can put files into skip-worktree for this. Works locally and needs to be setup at every developer PC.

https://compiledsuccessfully.dev/git-skip-worktree/

It might take some time (amount of commits merged) till the configuration files are all merged into one, but after that you only need to pay attention to the configurations when you actually change them.

  • Related