-1

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
Rishikesh Raje
  • 8,556
  • 2
  • 16
  • 31
  • https://stackoverflow.com/search?q=%5Bgit%5D+shallow+branches – phd May 11 '20 at 14:53
  • @phd - The above question is regarding clone. My question is regarding git fetch with --depth option. I looked at the answer and it did not resolve the issue. The approved answer resolved my problem, – Rishikesh Raje May 12 '20 at 02:30

1 Answers1

1

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
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • This worked. Thanks. It is odd that the behaviour is different for a shallow fetch. Also I found out that I need to do a git remote set-branches origin branchname to set up remote tracking – Rishikesh Raje May 11 '20 at 11:03