Note that there are some explanatory texts on larger screens.

plurals
  1. POGit: merging public and private branches while while keeping certain files intact in both branches
    primarykey
    data
    text
    <p>I've read a few git questions here, but could not find an answer to this one:</p> <p>I have a public and a private branches where I want to allow certain files to diverge.</p> <p>Those are configuration files with passwords and my local customizations. </p> <p>I do want to be able to merge the branches both ways: from private to public and back, but I do not want to ever have those specific files merged automatically.</p> <p>Is there a way to set up git this way? I'd love to find an automated solution :) - so that merging could be done as usual.</p> <hr> <p><strong>EDIT:</strong> here's the solution that worked for me (Thanks to VonC for the advice on gitattribute)</p> <p>the only unexpected thing for me was that "merge protection" starts working only after files have diverged in the two branches, not immediately after the following configuration was applied</p> <p>.gitattributes (track with git if you want to share this) or .git/info/attributes:</p> <pre><code>file1 merge=keepmine path/file2 merge=keepmine </code></pre> <p>keepmine is the named custom merge manager that is just a do-nothing command called instead of the internal merge driver on selected files, which is set up below</p> <p>When merging from private to public branch I usually do <code>git merge --squash private</code>. That way private edits won't get into the git history on the public branch.</p> <p>.git/config:</p> <pre><code>#public repository [remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* url = &lt;public repo git url&gt; #private repository #has to set up with git init and populated with the initial commit to branch mybranch [remote "private"] push = +: url = /path/to/local/private/repo [merge "keepmine"] name = dont_merge_selected_files driver = echo %O %A %B [branch "master"] remote = origin merge = refs/heads/master #private branch settings [branch "mybranch"] remote = private merge = refs/heads/mybranch </code></pre> <p>if there's a way to improve this please comment</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload