Follow-up of this so-question: if I have a shallow clone, how to fetch all older commits to make it a full clone?
-
4Do you consider to mark @sdram's answer? That's the correct one. – Ionică Bizău Jul 13 '14 at 10:17
-
1Related: [Increase depth of shallow clone without fetching other branches](https://stackoverflow.com/q/56539456/5353461) – Tom Hale Jun 11 '19 at 08:27
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

- 4,087
- 1
- 28
- 35

- 9,226
- 2
- 17
- 18
-
55This 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/* – Peter Cordes Jul 29 '14 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. – Peter Cordes Jul 29 '14 at 21:45
-
32See also http://stackoverflow.com/questions/17714159/how-do-i-undo-a-single-branch-clone: `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 – Peter Cordes Dec 08 '14 at 23:50
-
This only works if the repo is marked as shallow. I can't remember how, but there are situations where you can end up with an incomplete repo without having explicitly done a shallow clone. @svick's https://stackoverflow.com/a/6802238/260122 is the answer that works every time. – clacke Apr 27 '17 at 05:45
-
4`git fetch --unshallow --update-head-ok origin '+refs/heads/*:refs/heads/*'` worked for me – gzaripov May 25 '20 at 09:32
-
@gzaripov's one-liner **did not** work for me. It resulted in a local snapshot of remote branches that could not be configured with tracking. The three-lines given in this answer, however, do work. – M. Anthony Aiello Sep 17 '20 at 15:27
-
This is the only solution that @Peter_Cordes posted, that worked for me – Prometheus Oct 28 '20 at 10:24
-
See also https://stackoverflow.com/a/27393574/475821: `git remote set-branches origin '*'` does similar thing – esmirnov Sep 10 '21 at 07:13
-
@gzaripov under what circumstances is using the porcelain `--update-head-ok` useful? – Tom Hale Feb 08 '22 at 09:06
-
3`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. – Sridhar Sarnobat May 25 '22 at 04:05
-
Note: this option is available to `git pull`, as well, i.e., `git pull --unshallow`. – TravisCarden Aug 29 '22 at 14:36
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.
-
266Now that `git fetch --unshallow` exists (as in @sdram's answer), this answer is no longer the best one. – Jack O'Connor Apr 14 '14 at 08:41
-
1@sdram's answer did not work for me (git version 2.1.1), but this answer did. – Kijewski Nov 07 '14 at 14:48
-
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 – Tyguy7 Sep 19 '15 at 00:08
-
5`git fetch --depth=2147483647` is the largest possible depth to provide to the command. – clacke Apr 27 '17 at 05:47
-
9I used `git fetch --unshallow`, but it still does not show all the branches. – Sid Oct 03 '17 at 14:29
-
3@Sid, https://stackoverflow.com/questions/11623862/git-fetch-doesnt-fetch-all-branches fixed that for me. – Bryan Larsen Oct 10 '18 at 13:25
-
Tip: on an unstable internet connection, we can incrementally `git fetch --depth=1000` then again `git fetch --depth=10000` and so on. – Zzz0_o Apr 07 '21 at 11:19
-
Use of `git fetch --depth=2147483647` is sufficient within Azure DevOps Pipeline. – kris Mar 23 '23 at 08:13
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.

- 13,115
- 3
- 57
- 91
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

- 3,288
- 1
- 26
- 35

- 161
- 1
- 3
-
I only needed step F. I did `git clone --depth=1
`, but then `git fetch --unshallow` did not fix it, nor did `git fetch --all`: remote branch list still just had master & HEAD. Step F fixed it. – Tom Aug 20 '21 at 21:26
You can try this:
git fetch --update-shallow

- 2,237
- 27
- 30
- 38

- 21
- 1
-
--update-shallow doesnt work if shallow clone is performed with depth value. – Renuka Kulkarni May 18 '23 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

- 229
- 3
- 12
-
1What's the downvote for? Please explain so I can improve upon this. Thank you. – Gen.Stack Dec 15 '20 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. – Kevin Buchs Jan 29 '22 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

- 759
- 11
- 25