Closed adnan360 closed 2 years ago
page https://stackoverflow.com/questions/58537850/git-keep-depth-1-on-pulls-to-reduce-repo-size tells that after cloning with dephi 1, we cannot do 'git pull'? it is not ok.
... after cloning with dephi 1, we cannot do 'git pull'? it is not ok.
This is probably not true. git pull
will work on a shallow cloned repo, it will just not be a shallow clone anymore. It will add later commits to the repo history up to the latest one. So instead of one commit there could be multiple commits.
But it is not true that "we cannot do 'git pull'". We can.
For example:
$ git clone --depth 1 https://github.com/Alexey-T/CudaText
...
$ cd CudaText
$ git log --oneline
213c94e (grafted, HEAD -> master, origin/master, origin/HEAD) txt
## After a few hours
$ git pull
...
Updating 213c94e..cf06c9c
...
$ git log --oneline
cf06c9c (HEAD -> master, origin/master, origin/HEAD) cmt
4c07ed7 move IsSetToOneInstance to proc_globdata
213c94e (grafted) txt
Although there could be a way to keep it a shallow clone. I have used git pull --depth 1 --rebase && git gc --prune=all
in some repos for local use which worked fine for me. Just haven't used this for serious use cases or for pushing code from those.
There is a space issue in the link you shared. The above command might not be enough to get space savings. I have tested on nearly a year old cloned repo and ran the above command. It updated fine and made it contain only a single latest commit, but doing a new shallow clone showed a smaller size (55M) than older the one (76M). So I tried with some new commands added:
git pull --depth 1 --rebase
git tag -d $(git tag -l)
git reflog expire --expire=all --all
git gc --prune=all
And it worked. It brought down the size of the old repo to same as a new shallow clone:
$ du -hs FastLBRY-terminal*
55M FastLBRY-terminal_new
55M FastLBRY-terminal_old
Since this PR has been merged I'll post a new PR for this. We can further discuss on that PR.
git clone --depth 1 ...
causes it to clone only the last commit and a single branch which saves a lot of time and disk space when building. For building, we don't need full history and other branches anyway (at least as much as I tested).For time, it can save minutes. For space, it saves megabytes: