0

I have setup my build tool on different Git branches. e.g. develop, QA, stage, prod. code pushed in develop will build and deploy to develop environment and similar for other Git branches. So code changes are first pushed to develop. after dev verification, develop branch is merged with QA and so on.

The problem I am trying to solve is that I have environment specific configuration files that should not move to next branch on merge. So currently if I make change in dev specific setting file, and commit to develop branch. When develop branch is merged with QA branch, the settings changes are passed to QA also.

How to skip merging files or folder in git branch merge.

vikas sharma
  • 83
  • 2
  • 7
  • 4
    These environment specific files should be described in your [`.gitignore`](https://git-scm.com/docs/gitignore) file. – Romain Valeri Mar 04 '20 at 09:28
  • @RomainValeri gitignore is to avoid committing few files or folders as per my understanding. I need to commit changes in settings file. But during branch merge these changes should not move to next branch. Can this this be done using gitignore? – vikas sharma Mar 04 '20 at 09:39
  • 3
    I think it's not the way you should go. Something is part of project or not, if it's not part of project, it shouldn't be in repo, if it is part of project, you should include it. Config files usually aren't part of project and config file templates may be used instead. – Tupteq Mar 04 '20 at 09:44
  • The short answer is no. The long answer is still no, but with all the details about why not. You *can* write a *merge driver*, but it won't be invoked sometimes, and when it isn't, it won't do the job. See https://stackoverflow.com/search?q=%5Bgit%5D+merge+driver – torek Mar 04 '20 at 17:45

2 Answers2

1

What you want to do is actually not merge the whole branch with an other one but merge selective changes from one branch to another. And as you mentioned in the comments, .gitignore is not the right way to do that.

The answer has already been given in this question: How to selectively merge or pick changes from another branch in Git?

Basically the important thing is to have your configuration files changes gathered in one or several commits that are different from the code changes commits; it is very important to think in terms of commits instead of files. Then you can use git cherry-pick to apply the commits you want to the other branch.

Finally if this sounds too complicated maybe the configuration data could be removed from the repository and stored in separate files (then only one branch would be needed) in an ansible repository.. just a thought.

Christophe Muller
  • 4,850
  • 1
  • 23
  • 31
-1

It's possible to store files on a branch, but not include them to pull request

Check here for details