I have previously done a git shallow clone with --depth 1
After that, I want to get a specific branch from the remote with a depth of 10 and checkout to that branch.
I am able to fetch the branch from remote, but it the branch is not showing at git branch -a
The log after replacing personal information is below
User@PC-NAME MINGW64 /d/Folder/application (master)
$ git fetch --depth 10 origin branchname
remote: Counting objects: 18624, done.
remote: Compressing objects: 100% (10327/10327), done.
remote: Total 18624 (delta 12993), reused 12045 (delta 7599)
Receiving objects: 100% (18624/18624), 530.73 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (12993/12993), completed with 3067 local objects.
From 10.100.x.x:Repository/application
* branch branchname -> FETCH_HEAD
User@PC-NAME MINGW64 /d/Folder/application (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
The default refspec in a shallow clone only mentions refs/heads/master
(not refs/heads/*
as in a "regular" clone), so git fetch
does not know what local reference should be updated when you only mention branchname
.
For a one shot update, mention the explicit refspec on the command line :
git fetch --depth 10 origin branchname:refs/remotes/origin/branchname
For a recurring update, add the refspec in your .git/config
:
# at the end of your [remote "origin"] section :
fetch = refs/heads/branchname:refs/remotes/origin/branchname