How to clone seed/kick-start project without the whole history?

GitGit CloneShallow Clone

Git Problem Overview


Note that using --depth=1 parameter prevents you from pushing the project to a new repository.

Git Solutions


Solution 1 - Git

You can do a

git clone <git_url>

delete the .git repository from your folder. Which will delete all your history.

The you can do a

git init 

which will create an entirely new git project for you.

This may not be the best way. But this will work . Hope it helps.

Solution 2 - Git

As long as you consider full loss of history to be no issue, the approach suggested by Ajay is perfectly valid. But in case you want to maintain the history of your shallow clone I have a different suggestion.


A shallow clone pretends to have the full history by using a so called graft point to fake the parent of the "first" commit. If we assume that we have the full history available, we could rephrase the question: How can I throw away the history before a specific revision?

This means we can use a combination of a graft point and git filter-branch (as suggested in the linked question). However you have to note that this will rewrite your full history, making the new one incompatible with the remote we initially cloned from. Due to this, we should remove the old remote from our repository.

git remote remove <old-remote-name>

Now we can start our rewrite. Let's assume that we want to make the current master commit the new root for the repository.

git rev-parse --verify master >> .git/info/grafts
git filter-branch -- --all

This will rewrite the full history of our repository, with the current master commit as the new root. You can finalize the rewrite by removing the "backup" references in refs/original. Furthermore you can now delete the .git/shallow file.

After you've done this, you should be able to push the now ungrafted history in your new remote.

Solution 3 - Git

Try something like this:

mkdir -p /tmp/git-copy
cd /tmp/git-copy

# create another copy of your repository
git clone file:///path/to/cloned/repo

cd repo
git rebase -i (first-commit)

# in vim:
# :2,$s/^pick/squash
# :w

# Now wait, it will take a while...

git push --mirror [email protected]:username/new-repo.git

I tried it just now on this repository. Seems to work - no history and all submodules are intact.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionitamarView Question on Stackoverflow
Solution 1 - GitAjayView Answer on Stackoverflow
Solution 2 - GitSascha WolfView Answer on Stackoverflow
Solution 3 - GitAleksander AlekseevView Answer on Stackoverflow