I'm looking for a practical way to work on a private and public repository where the private repository's contents in a specific folder may diverge from that in the public branch. This folder must exist in both branches, and its content tracked in both repositories but must never be merged.
This is the simplified setup of the repository:
/folderA <-- public content
/folderB <-- mixed public & private content
/folderB/private.files <-- this file is different in public & private repos
/folderB/newPrivateFolder <-- private repo may add more private-only folders here
These are my seemingly simply requirements, yet I haven't found a good working solution:
private.files
must exist in the public repo with default content for the project to work private.files
in public repo should not be merged with private repoprivate.files
changes must be tracked in private repo as it's needed by team members private.files
in the private repo must never be merged with public repofolderB
in private repo must never be added to public repoThe private repo is a duplicate of the public repo.
What I have tried:
What I haven't tried yet:
Anything else I could try?
Perhaps there's already a solution to this issue - but I've been looking at dozens of SO and dozens more articles on the web, yet there's seemingly no solution to this diverging folder contents issue.
in similar situations (deployment to differing installations with small local but permanent modification) i have used a master branch that includes nothing or dummy files in the folders in question. then for every local configuration (that would be private and public in your case) i created a branch off master and did the relevant changes there.
development takes places on master and occasionally i switch to the other branches (private / public) and merge from master to these branches, never the other way round.
the different configurations (private / public) only share code from master, not the local modifications, i can keep them for an indefinite time, and i still have one and only one central place for changes/development (the master branch).
It seems so simple now that I figured it out. In essence you just delete folderB on merge and replace it with its public contents, then commit.
Basic setup requires:
Now when the private repo has made modifications & additions to both folderA and folderB and you want to merge all changes except those in folderB back to the public repo, you merge as follows (I suggest an additional merge branch to safely experiment with it):
git checkout merge-branch
git merge -s recursive -Xtheirs --no-edit --no-commit private-branch
rm -rf folderB
git reset <tree-ish> -- folderB/
git checkout --theirs <tree-ish> -- folderB/
What this does:
I'm not sure if both reset AND checkout are necessary but I'm doing it anyway. Feel free to experiment.
As a consequence, the commit history of any changes to folderB in the private branch will not be added to the public repo if you clean out the working directory after the merge and before committing.
I tried experimenting with a post-merge hook to do the job, but it doesn't seem to run if you don't commit. Besides it is easier to just put all commands in one script.
Merging public repo changes back to the private repo works normally, no additional steps are required.
As .git does NOT support .ignore (via remote or branch differences); here is my simple work-around in NPM:
"scripts": {
"deploy:public": "git add . && git commit -am 'master src committed'",
"deploy:private": "git add . && git rm -r --cached src/* && git commit -am 'master src omitted.'" }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.