You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Repository has no commit" error in case of worktree + packed-refs #1290
After git decided to pack my repo with several worktrees and a bunch of local branches, my builds started failing with following error:
D:\Corextroot\microsoft.build.tasks.git\8.0.0\build\Microsoft.Build.Tasks.Git.targets(25,5): Repository has no commit. [D:\Pl3\Test\UnitTests\Common\Tools.UnitTests.Common\Tools.UT.Common.csproj]
D:\Pl3 is a worktree of D:\Platform.
D:\Platform\.git\worktrees\Pl3\refs is empty.
D:\Platform\.git\refs\heads doesn't have a ref of a branch that's checked out in D:\Pl3 either
The only reference to the commit ID of a branch specified in D:\Platform\.git\worktrees\Pl3\HEAD is in D:\Platform\.git\packed-refs
Sourcelink task is unable to handle this situation.
I have worked to add a unit test that covers my scenario: #1289
The issue went away after I created the very next commit, which created D:\Platform.git\refs\heads\user\vikukush\mstestv3 file, so the commit ID was no longer inside packed-refs.
So the bug can be easily worked around, but this of course still needs to be fixed.
I'm hitting this too. I'm using Microsoft.Build.Tasks.Git from .NET SDK 10.0.105. It seems this happens when the HEAD ref is packed, i.e., there is no file under refs/heads/ for it in .git folder, it's only in .git/packed-refs. Can be worked around by creating a new commit (since that one won't be packed yet).
I tried to repro with out of our repos, using git pack-refs --all -- this removed refs/heads files but source link was still working (getting the commit sha from the packed refs).
Activity
vikukush commentedon Oct 2, 2024
The issue went away after I created the very next commit, which created D:\Platform.git\refs\heads\user\vikukush\mstestv3 file, so the commit ID was no longer inside packed-refs.
So the bug can be easily worked around, but this of course still needs to be fixed.
bradwilson commentedon Mar 13, 2026
I just started using
git worktreeand ran into this.Any progress here, or even an acknowledgment from the team that it's an issue to be fixed?
tmat commentedon Mar 13, 2026
Will take a look.
tmat commentedon Apr 21, 2026
The path
D:\Corextroot\microsoft.build.tasks.git\8.0.0indicates that you're using .NET SDK 8.0. Does the issue reproduce with .NET SDK 10?jjonescz commentedon Apr 21, 2026
I'm hitting this too. I'm using Microsoft.Build.Tasks.Git from .NET SDK 10.0.105. It seems this happens when the HEAD ref is packed, i.e., there is no file under refs/heads/ for it in .git folder, it's only in .git/packed-refs. Can be worked around by creating a new commit (since that one won't be packed yet).
tmat commentedon Apr 21, 2026
@jjonescz Do you have repro steps how do you get the repo to that state?
jjonescz commentedon Apr 21, 2026
I can try to create a small repro if you want. But based on my analysis, if you use
git pack-refsto make the current HEAD a packed ref, that should be it. It seems there is even a PR with a unit test for this (which seems correct at a high level to me): https://github.com/dotnet/sourcelink/pull/1289/changestmat commentedon Apr 21, 2026
I tried to repro with out of our repos, using
git pack-refs --all-- this removed refs/heads files but source link was still working (getting the commit sha from the packed refs).tmat commentedon Apr 21, 2026
Never mind. I think I see the issue. The docs https://git-scm.com/docs/git-pack-refs say the
packed-refsfile is in$GIT_DIR, but it's actually in$GIT_COMMON_DIR. This is mentioned in https://git-scm.com/docs/gitrepository-layout#Documentation/gitrepository-layout.txt-packed-refs.