I had a massive git repo because of a huge number of commits, so following advice here I created a shallow clone. I've made changes to this new local repo, and now I want to push to my origin at Github (and then on to my staging and production remotes on Heroku). Perhaps one day I'll learn to read the documentation:
The git clone --depth command option says
--depth Create a shallow clone with a history truncated to the specified number of revisions. A shallow repository has a number of limitations (you cannot clone or fetch from it, nor push from nor into it)
So... how can I unpick myself from this situation and push my code to Github?
Git (since 1.8.3) now has an official way to fetch the full history of a shallow clone:
git fetch --unshallow
From the git fetch documentation:
--unshallow
If the source repository is complete, convert a shallow repository to a complete one, removing all the limitations imposed by shallow repositories.
If the source repository is shallow, fetch as much as possible so that the current repository has the same history as the source repository.
I will not agree with the accepted answer for 2 reasons:
Here are my suggestions:
You should have a $GIT_DIR/.git/shallow file with a graft point. If the history is simple enough, this graft point should allow you to push even though documentation says otherwise.
This allows you to keep commit history and etc:
git format-patch origin..master
Then clone the origin and reapply:
git clone origin_path
cp shallow_clone/*.patch deep_clone
cd deep_clone
git am *.patch
This time you can push !
git push
If you are working in a shallow clone and the lack of history is causing a problem, you can fetch more history with the --depth
option.
git fetch --depth=20
Where 20 is is the amount of commits to fetch. Increase it if that is not enough.
You can also use the --depth
option with git pull
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With