How do I fork a subset of a git repository without history?

Go To StackoverFlow.com

4

Suppose I have git repository like this:

git-repo/
    directory_1/
    directory_2/
    directory_3/

This has a long history, and the history contains some code that I don't want anyone to have access to. I also don't want to release directory_1.

I want to release directory_2 and directory_3, but with no history information. Going forward, I will be continuing development in the original repository, and would like to also update the release fork with these changes.

The original repository is hosted as a private repository on github right now.

How should I do this?

2012-04-04 01:07
by NoName
I don't think git makes this easy. There's probably a better way, but you could make a fork, git rebase -i until you have the history you like, and cherry-pick future updates from your original repository - A B 2012-04-04 01:11
If you want separate permissions, you should be using separate repositories - Borealid 2012-04-04 01:16
@Borealid. I assume that I'll need to use separate repositories. How do I get there from where I am now - NoName 2012-04-04 01:18
@alberge, I like that suggestion. What would the cherry-picks look like? The commits to the original will be updating directories 1, 2, and 3, but I'd only want to cherry-pick the updates to directories 2 and 3 over to the release fork - NoName 2012-04-04 01:23
You'd have to individually cherry-pick any commit that touched those directories. With git it is much easier to have separate repositories for 1, 2, and 3 if you want to maintain separate history - A B 2012-04-04 01:36
Are you going to be developing in the new (public) repo? It sounds like you might just want a repo that's only updated via an occasional "git export" from the private repo - blahdiblah 2012-04-04 02:36
@blahdiblah, I would not be developing in the new (public) repo. Yeah, git export might be good enough - NoName 2012-04-04 05:03
Is there a way to merge changes in the new repo back to the original one - kerner1000 2017-03-23 19:20


1

Given your clarification, it sounds like this setup could work for you:

  1. Make a new public repo with the git exported parts of your private repo that you want to share.
  2. To update, replace the contents of the public repo with a fresh git export from the private repo.

The public repo won't inherently share any history with the private repo, but it sounds like that might not matter much for your purposes.

2012-04-04 05:28
by blahdiblah


0

I would first go to the download page for your private repo, something like

github.com/jquery/jquery/downloads

Here you can simply get the files from the current repo with no history. After that you can create a new repo, and git commit in only the files/folders that you are wanting on the new repo.

2012-07-24 13:49
by Steven Penny
Ads