UditG UditG - 1 year ago 151
Git Question

How to git merge changes from main branch to orphan branch without adding to orphan's history?

I have a git repository for my phd dissertation (in latex). The university policies does not allow me to share the background review chapter of my dissertation with my research adviser, I am free to share and get opinion for other chapters.

To share the repository with my advisor I created an orphan branch (noRevBranch) with the required chapter removed and pushed and tracked this branch to a new repository on github.
I can share this with his and he can not access the removed chapter because there is no history here.

The question is how do I merge any changes I make to the master branch in the future to the noRevBranch without also appending the master branch history to the new merge commit?

Answer Source

You can leave the structure as its right now.
What you can do is to use git cherry-pick <range of commits> to commit all the new commits to the "orphan" branch.

git cherry-pick <SHA-1>...<SHA-1>

Apply the change introduced by the commit at the tip of the master branch and create a new commit(s) with this change.

The syntax of the ... is a commit range. grab all commits from start (exclude) to the last one.

enter image description here

Read out the full git cherry-pick documentation for all the options you can use