1

I'm extracting a subset of one repo to form another. I'm only interested in a subset of the branches and I don't want any history in any branch, simply the tip or head of each branch.

Once the cloned repo is in the desired state I intend to change its origin to a new GitHub repo and push, which rules out a shallow clone.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
Myles McDonnell
  • 12,943
  • 17
  • 66
  • 116

1 Answers1

1

You can do a shallow clone, but for the all repo (not a subset).

Otherwise, you could try git archive, which can archive a path within a tree.
See also "How can I git archive an arbitrary branch?".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks VonC. I looked at shallow clone, but, quote from man page: A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it), but is adequate if you are only interested in the recent history of a large project with a long history, and would want to send in fixes as patches. --- and I need to push to the new origin on GitHub – Myles McDonnell Nov 28 '12 at 14:03
  • @MylesMcDonnell still you can shallow clone, then add a GitHub remote address, and try a push. As long as you don't work directly from that shallow clone, but rather clone the full history of your new Github repo, you should be ok. – VonC Nov 28 '12 at 14:18
  • Sorry, I'm confused now. Why do I need to clone my new git repo? My new git repo exists on GitHub. My shallow clone exists locally. I change the origin of the shallow clone to the new rep on GH, try to push and I get error: failed to push some refs to {remote url} it clearly says in the docs that you can't push from a shallow clone. what am I missing? thanks again :) – Myles McDonnell Nov 28 '12 at 15:06
  • @MylesMcDonnell ok, then remove the `.git` locally, do a `git init`, and `git add` and `git commit`, then add the GH remote and push. Ie, recreate a clean git repo from your shallow clone. That would take, however, only one branch into account. If you want several, create an empty git repo, and import each branch content into it (`git checkout` in both repos, the shallow one and the empty one, and copy the content from the shallow one to the empty one for each branch). Then push to GH. – VonC Nov 28 '12 at 15:10
  • @MylesMcDonnell I have edited my last comment to preserve the branches. – VonC Nov 28 '12 at 15:13