1

I have two branches master and develop. Each branch contains a same file named "db.config" having a separate db credentials for production(master) and staging(develop).  

Master branch also have .gitattributes file in which i defined a merge=ours strategy for db.config

.gitattributes

db.config merge=ours

When i merge develop into master branch by creating a pull request in bitbucket then changes in develop branch also goes to master after merge for db.config. It looks like .gitattributes file doesnot work for me. 

Also stackoverflow same issue doesnot works for me. Does anyone know how i get rid out of this?

Jawad
  • 39
  • 1
  • 5
  • 1
    TL;DR: you *can't* ignore a file during merge. Using `.gitattributes` doesn't do that. *Sometimes*, by defining a merge driver, you can cause the *effect* of a merge to be what you want. The file was not ignored! This *sometimes* does not apply at all times, Don't do this, you'll just make your own life miserable. – torek Dec 21 '19 at 21:32
  • @torek is their any other way to do this in our actual project? – Jawad Dec 22 '19 at 00:44
  • Not really. In general, files that aren't meant to be merged should never be committed in the first place. Configurations should have *prototype* or *example* files committed; the actual configuration should be stored elsewhere, not in the repository. – torek Dec 22 '19 at 00:48

1 Answers1

0

I've been able to replicate your issue, and pretty sure you forgot that part:

And then define a dummy ours merge strategy with:

$ git config --global merge.ours.driver true

From your master branch.

Switch to master, configure your merge strategy, it should work.

Whats the Proper usage of .gitattributes with merge=ours

Edit: due to what had been said in the comments, you probably want to remove this file from tracking:

How to stop tracking and ignore changes to a file in Git?

Olegp
  • 182
  • 2
  • 14
  • 1
    I also tried this but it doesnot worked when i am creating a pull request and then merge a branch in bitbucket using default merge strategy. – Jawad Dec 21 '19 at 21:40
  • @Jawad don't forget that PR merges remotely so `git config --global merge.ours.driver true` has no effect in PR – Yuri G. Dec 22 '19 at 04:04