Skip to content

Shared Repo No History

In this page we're looking at ways of taking an existing repo that potentially has lots of history including maybe some sensitive stuff, and being able to create a shallow fork of the repo that doesn't include all the history, but can be pushed,pulled and merged to and from.

BEWARE

do not blindly merge our master or other branches into Bob's.

If we need ot merge code into Bob's, I am not yet certain what the best technique is

This is definitely an Alpha in terms of a recommended practice, it's a not properly tested

How to do it

We do this using an orphan branch

It might look something like this:

Assume we want to create a private repo on Github which is a fork of our main repo.

Let's assume our third party is called Bob

First, create the repo on Github and ensure it's private. The project is called "project name" so we will call the repo project-name-bob

To make our lives simple, we are going to ask Bob to prefix all his branch names with bob- and we will do the same, our first branch is going to be called bob-master.

Now we can

cd project-name
git checkout master
git checkout --orphan bob-master
At this point we have created a new orphan branch. It has no history, no commits whatsoever, so the first thing we need to do is add all the files. This is of course a good time to double check you are really ignoring everything you should be.

git add -A
git commit -am 'initial commit'

Now we have added the files and create the first commit on this new branch. Now it's time to push it up to Github. To do that, first we need to set up the remote

git remote add github-bob git@github.com:edmondscommerce/project-name-bob.git
git push github-bob bob-master

On github you will now have one branch called bob-master. Bob can clone this repo down, make feature branches etc from bob-master and ultimately merge them into bob-master. He can ask us to pull down his work

When Bob has done some work and we want to pull it, simply run

git checkout bob-master
git pull github-bob bob-master

We can review Bob's work and ultimately decide to merge it into our master branch etc as normal.

Further Reading

https://git-scm.com/docs/git-checkout#Documentation/git-checkout.txt---orphanltnewbranchgt

https://stackoverflow.com/questions/27641380/git-merge-commits-into-an-orphan-branch