Home > Blockchain >  how create a new git repo whose first commit is the last commit of the source (no history, not linke
how create a new git repo whose first commit is the last commit of the source (no history, not linke

Time:04-13

How do I create a clone of a git repo that contains only the master branch, and only the most recent commit, AND can be pushed to a new repo at github/bitbucket/etc?

I've got a large git repo... couple of GB... that grew over a decade... lots of obsolete binary cruft... lots of old branches. That's the current legacy app.

We're creating a new app and want to create a new repo that contains only the current commit and the master branch.

I thought maybe I should do some sort of shallow clone like git clone --depth [depth] [remote-url] but

a) I'm not sure how to also not include any branches except master?

b) more importantly, the problem with git clone --depth is it creates some kind of 'grafted' commit, which cannot then be pushed to github (the "shallow update not allowed" issue).

I should mention, in this case, I have the legacy repo on the same computer, in case the "right answer is to simply copy the project folder and trash the .git folder. But I'm hoping as a more general solution that there's git-way to do it.

CodePudding user response:

I suggest you to try with:

git clone --depth 1 --single-branch --branch master <REPO-URL>

CodePudding user response:

Create an orphan branch from the head of the current master.

git checkout --orphan foo master
git commit

Push foo to the new repository.

git push <url_to_new_repo> foo:refs/heads/bar

As you mentioned a lot of binaries, I suggest you use git lfs to track them.

  •  Tags:  
  • git
  • Related