Follow-up of this so-question: if I have a shallow clone, how to fetch all older commits to make it a full clone?
7 Answers
The below command (git version 1.8.3) will convert the shallow clone to regular one
git fetch --unshallow
Then, to get access to all the branches on origin (thanks @Peter in the comments)
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin
-
59This doesn't undo the --single-branch side effect. To do that, edit .git/config and change fetch = +refs/heads/BRANCHNAME:refs/remotes/origin/BRANCHNAME to fetch = +refs/heads/*:refs/remotes/origin/* Commented Jul 29, 2014 at 21:36
-
4This doesn't create local branches tracking the remote branches, so you still need to checkout -b BRNAME origin/BRNAME to get that set up. Commented Jul 29, 2014 at 21:45
-
34See also stackoverflow.com/questions/17714159/…:
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*";
git fetch origin
from an answer there should be the same as editting .git/config by hand Commented Dec 8, 2014 at 23:50 -
6
git fetch --unshallow --update-head-ok origin '+refs/heads/*:refs/heads/*'
worked for me– gzaripovCommented May 25, 2020 at 9:32 -
4
fatal: --unshallow on a complete repository does not make sense
If 799 people agree, something must be wrong at my end. I've yet to determine what. Commented May 25, 2022 at 4:05
EDIT: git fetch --unshallow
now is an option (thanks Jack O'Connor).
You can run git fetch --depth=2147483647
From the docs on shallow:
The special depth 2147483647 (or 0x7fffffff, the largest positive number a signed 32-bit integer can contain) means infinite depth.
-
268Now that
git fetch --unshallow
exists (as in @sdram's answer), this answer is no longer the best one. Commented Apr 14, 2014 at 8:41 -
2Neither answer worked for me. Both commands succeeded in fetching all the missing commits, but when I try to push new commits, I get an error about the server not knowing about 'shallow' refs– Tyguy7Commented Sep 19, 2015 at 0:08
-
6
git fetch --depth=2147483647
is the largest possible depth to provide to the command.– clackeCommented Apr 27, 2017 at 5:47 -
11I used
git fetch --unshallow
, but it still does not show all the branches.– SidCommented Oct 3, 2017 at 14:29 -
3@Sid, stackoverflow.com/questions/11623862/… fixed that for me. Commented Oct 10, 2018 at 13:25
I needed to deepen a repo only down to a particular commit.
After reading man git-fetch
, I found out that one cannot specify a commit, but can specify a date:
git fetch --shallow-since=15/11/2012
For those who need incremental deepening, another man
quote:
--deepen=<depth>
Similar to --depth, except it specifies the number of commits from the current shallow boundary instead of from the tip of each remote branch history.
Two ways to achieve Shallow Clone to Deep Clone. :
Used the following steps to download the branch: (This downloads the shallow copy of the branch and then converts it into a Full Clone i.e bring complete branch and its history).
a. git clone -b branch http://git.repository/customSP01.git --depth 1
This does a shallow clone (with the depth-option) only fetches only one single branch (at your requested depth).
b. cd customSP01
c. git fetch --depth=100
d. get fetch --depth=500
....
e. git fetch --unshallow
//The above command will convert the shallow clone to regular one. However, this doesn’t bring all the branches:
Then, to get access to all the branches.
f. git remote set-branches origin '*'
[This Step can also be done manually by editing following line in .git/config.
fetch = +refs/heads/master:refs/remotes/origin/master
to (replace master with *):
fetch = +refs/heads/*:refs/remotes/origin/* ]
g. git fetch -v
This converts the Shallow Clone into Deep Clone with all the History and Branch details.
You can avoid steps f and g, if you use the below instead of command present in step a. to do the shallow clone:
git clone -b branch --no-single-branch http://git.repository/customSP01.git --depth 1
-
I only needed step F. I did
git clone --depth=1 <url>
, but thengit fetch --unshallow
did not fix it, nor didgit fetch --all
: remote branch list still just had master & HEAD. Step F fixed it.– TomCommented Aug 20, 2021 at 21:26
You can try this:
git fetch --update-shallow
-
--update-shallow doesnt work if shallow clone is performed with depth value. Commented May 18, 2023 at 15:31
None of the above messages did the trick. I'm trying to work with git tags starting from a shallow clone.
First I tried
git fetch --update-shallow
which kind of worked half-way through. Yet, no tags available!
git fetch --depth=1000000
This last command really fetched the tags and I could finally execute
git checkout -b master-v1.1.0 tags/v1.1.0
and be done with it.
HTH
-
1What's the downvote for? Please explain so I can improve upon this. Thank you. Commented Dec 15, 2020 at 12:10
-
I didn't downvote, but I think it might be because 'git checkout -b' is used to create a new local branch. So, I don't think it does what might be expected in the context of your answer. Commented Jan 29, 2022 at 19:02
Configurations that helped with the error is (In GitLab) For each project :
- On the top bar, select Main menu > Projects and find your project.
- On the left sidebar, select Settings > CI/CD. Expand General pipelines.
- Under Git strategy, choose git fetch, under Git shallow clone, enter a value, 1000, the maximum value for GIT_DEPTH Read More - https://gitlab.yourcompany.com/help/ci/pipelines/settings#limit-the-number-of-changes-fetched-during-clone{}
In the .gitlab-ci-yml (this should be done before any command that calls GitVersion.exe)
before_script:
- git fetch --prune --tags --unshallow