1

I am having two branches on GitLab(1.Staging & 2.Production). In my Angular and NodeJS application there is one part(e.g. Contact us ), which I don't want to deploy on production.

I want it in staging branch but not in production branch.

So my question is how can I skip the specific code during merging of two branches in GitLab.

I am using Merge requests button for merging. but I have .gitignore, .gitattributes & .gitlab-ci.yml files.

Please help me, Thanks in advance

Aary
  • 67
  • 1
  • 5
  • "Merge requests" are specific to GitLab (so questions about them should not use the [tag:git] tag), but your actual problem here has nothing to do with merge requests in the first place, as seen in [VonC's answer](https://stackoverflow.com/a/72123577/1256452) and the [linked question](https://stackoverflow.com/a/49051739/6309). – torek May 05 '22 at 19:45

2 Answers2

2

As explained here, there is no obvious way to have a file in one branch, but not (after a merge) in another.

If you can have that same file in both branches, but with a content (in prod) which would not be impactful, then you can put a merge driver in place in order to keep that prod content whenever you merge from staging.
However, this is a local solution, not one you can set when clicking Merge directly on GitLab.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

One option is deleting the unnecessary files in a pre-deploy stage only for production.

You can even edit files before deploying. For example, we use sed commands to update our settings file before deploy in production.

pre-deploy:
  <<: *default_config
  stage: pre-deploy
  image: $CI_REGISTRY_IMAGE:latest
  only:
    - production
  script:
    - echo "delete unnecessary  files"
    - # SED https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/
CharithJ
  • 46,289
  • 20
  • 116
  • 131