htmltester1322
htmltester1322

Reputation: 33

How to enable custom merge driver - .gitattributes in GitHub

I have develop and master branch. The develop branch should have different values of CODEOWNERS file from master branch. For example:

develop branch should have:

 * @user1 @user2 @user3 @user4 @user5

master branch should have:

 * @user1 @user2

I'm trying to ignore the changes of CODEOWNERS in develop branch from pull request/merging from GitHub Website. I added .gitattributes and added:

 CODEOWNERS linguist-generated
 CODEOWNERS -diff
 CODEOWNERS merge=binary
 CODEOWNERS merge=ours

But when trying to pull request from GitHub website(develop to master), the CODEOWNERS still showing that it has modified changes.

I'm not sure if this gonna work but I tried to add git config --global merge.ours.drivers true in my local machine. Still no luck. Should I add this config to the server where git is installed? What should I do to enable the custom driver. Thank you.

Upvotes: 1

Views: 774

Answers (1)

bk2204
bk2204

Reputation: 76804

GitHub does not support custom merge drivers. The command that is used to handle a custom merge driver is stored in the configuration and configuration is not shipped with the repository. As Edward Thomson pointed out, shipping any configuration that specified a program to use would be a security hazard as it would allow an attacker to execute arbitrary code, which is why Git doesn't offer that capability.

As a result, GitHub doesn't even know the command that's needed to run your custom merge driver and even if they somehow did, they wouldn't execute arbitrary code on behalf of users.

In general, the Git developers don't recommend trying to avoid merging files like this. If you absolutely need this feature, you need to use a bot to perform all these merges for you and allow only the bot to perform merges on your repository.

Upvotes: 1

Related Questions