Search code examples
gitversion-controlatlassian-sourcetree

how to except files from be merged to other git branch?


I have two branches: one for development and another for production, each one has its own config values in app.config file

what I want is to ignore these values whenever I merge or rebase these branches.


Solution

  • Then perhaps you best bet would be to not even version the app.config

    Exactly, but you can still generate it, with a content filter driver, using .gitattributes declaration.

    What you would version is a template file, and a file with all possible values per environment (per branch).

    smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

    The generated actual file remains ignored (by the .gitignore): your actual working tree does not get "dirty".

    The smudge script:

    • detect the right branch
    • selects the correct value file and generates the correct file based on the template the smudge script is applied on during a git checkout.

    That way, you modify the config.<branch> value file as much as you want: the config file (not versioned) will be generated from those values.
    And it won't have any merge issue.