Pushing to github after a shallow clone
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:
- There are many reasons to fail and forget a file
- You lose your commit messages and history
Here are my suggestions:
Graft point
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.
Patches
This allows you to keep commit history and etc:
git format-patch origin..master
Then clone the origin and reapply:
git clone origin_pathcp shallow_clone/*.patch deep_clonecd deep_clonegit 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
.