How to ignore yml and config files while merging one branch to another
Asked by Mukul Rana:

Hello Everyone,

I am facing this issue where when i merge my code from dev to stage pipeline , I get a merge conflict error on bitbucket-pipelines.yml and config.js.

It is a requirement that these two files stay different in both pipelines as they contain configurations specific to them.

I have tried adding .gitignore file with entry of yml file and config.js directly into the repo through UI but that doesn't seem to help

I also tried applying .gitattributes by following this answer on stackoverflow: [gitattributes](https://stackoverflow.com/a/3970442)

but i still get the merge conflict.

Any help would be much appreciated.

Thanks in advanced!


Answers:
author: Caroline R
body: Hi, [@Mukul Rana](/t5/user/viewprofilepage/user-id/5040448), welcome to the community!

Before we start, I would like to further understand the configuration you have in your repository. Do you have 2 yml files under this repo? Also, when you say that you are facing an issue when you merge your code from dev to stage pipeline, is it triggering a default definition in your pipelines?

If that's the case, you can actually have 1 YAML file under your repository and configure it to run specific sections for specific branches, this way, the names or expressions in this section are matched against branches in your Git repository. For example:

    pipelines:  default:      - step:          name: 'Build and Test'          script:            - echo "Your build and test goes here..."  branches: #these will run on every push of the branch    bug:      - step:           script:            - echo "I'm testing something here"

This document explains how to configure your bitbucket-pipelines.yml, in case you would like to take a look:

* <https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/>

Looking forward to hearing from you.

Kind regards,  
Caroline

comments: author: Mukul Rana
body: Thanks Caroline

We were able to solve this issue by rewriting our yml files in the way you suggested!


author: Mukul Rana
body: Hi ,

I missed an important part of the question.

With the help of your suggestion, i was able to reorganise my yml files and avoid merge conflict however my config.js file still shows merge conflict error.

Let me tell you more about our current scenario

We have a config.js in our stage pipeline and in production. It is necessary that these two files remain different. However, when we merge stage to production, we get a merge conflict on this file.

Can you suggest a way by which when i merge these files remain in thier original state or if i can say - Are ignored while merging.

Thanks!


author: Caroline R
body: Hi, [@Mukul Rana](/t5/user/viewprofilepage/user-id/5040448),

This is not possible as Git does not allow this. However, while searching for workarounds, I found the same questions on other sites that might help you:

* <https://stackoverflow.com/questions/15232000/git-ignore-files-during-merge>

* <https://stackoverflow.com/questions/38044166/how-to-exclude-files-from-merging>

They recommend running **git merge** with the `flag `**--no-commit** to avoid specific files.

I hope this helps, but let me know if you have questions.

Kind regards,  
Caroline


Tags: bitbucket-cloud

cloud