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
6 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
![](../../users/profiles/1151228.webp)
- 3,727
- 1
- 25
- 31
![](../../users/profiles/2400661.webp)
- 7,680
- 2
- 14
- 16
-
42This 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
-
3This 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
-
30See 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
-
1`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
EDIT: git fetch --unshallow
now is an option (thanks Jack O'Connor).
You can run git fetch --depth=1000000
(assuming the repository has less than one million commits).
![](../../users/profiles/1724702.webp)
- 15,841
- 3
- 36
- 54
![](../../users/profiles/41071.webp)
- 214,528
- 47
- 357
- 477
-
252Now 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. – kay 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
-
3`git fetch --depth=2147483647` is the largest possible depth to provide to the command. – clacke Apr 27 '17 at 05:47
-
5I used `git fetch --unshallow`, but it still does not show all the branches. – Sid Oct 03 '17 at 14:29
-
2@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
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.
![](../../users/profiles/207791.webp)
- 11,714
- 2
- 50
- 78
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
![](../../users/profiles/2565346.webp)
- 41
- 2
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
![](../../users/profiles/10050838.webp)
- 137
- 1
- 7
-
What's the downvote for? Please explain so I can improve upon this. Thank you. – Gen.Stack Dec 15 '20 at 12:10