Cause #1: The repository folder's owner isn't your user account
The most common reason Git throws this error on Windows is that the repository folder (or one of its parent folders) is owned by a different user account than the one you're running Git from. This happens a lot when you move a repo from another machine, clone it onto an external drive, or unzip a project that was created on a different computer.
Here's the error you'll see:
fatal: detected dubious ownership in repository at 'C:/Users/you/project'
'C:/Users/you/project' is owned by:
'S-1-5-32-544'
but the current user is:
'S-1-5-21-...'
That long string starting with S-1-5 is a Windows security identifier (SID). When Git sees that the owner of the folder isn't the same as the current user, it refuses to run because it's worried about symlink attacks or other security tricks.
How to fix it
The proper fix is to take ownership of the folder with your current user account. Here's the step-by-step:
- Open File Explorer and go to the folder that contains your Git repo (the folder that has the
.gitsubfolder). - Right-click the folder and select Properties.
- Go to the Security tab.
- Click the Advanced button (it's at the bottom).
- You'll see a box that says "Owner: ...". On the right, click Change.
- In the "Enter the object name to select" field, type your Windows username. If you're not sure, type
Everyone— that works in a pinch, but it's better to use your own account. - Click Check Names, then OK.
- Check the box that says Replace owner on subcontainers and objects. This makes sure it also fixes any subfolders.
- Click OK until you're back to the Properties window.
- Click OK to close Properties.
After you do that, go back to your terminal and run your Git command again. It should work now. If you still get the error, try closing your terminal and reopening it—sometimes the Git process caches the old state.
One thing to note: if the repo is on a network drive or a removable drive, the owner change might not stick. In that case, use the next fix.
Cause #2: Git's safe.directory setting is missing
If changing ownership doesn't fix it, or you can't change ownership (like on a company-managed laptop), the next option is to tell Git to trust that specific folder. Git has a setting called safe.directory that lets you whitelist directories that are owned by other users.
You can add your repo to the safe list with this command:
git config --global --add safe.directory C:/path/to/your/repo
Make sure you use forward slashes and the full path to the repo folder. You can copy the path from the error message—just replace the backslashes with forward slashes.
If that works, but you have many repos scattered around, you can add a wildcard path:
git config --global --add safe.directory *
But be careful with that. That tells Git to trust everything, which defeats the purpose of the check. I only recommend it on a personal machine where you're the only user and you trust all the folders on your system. On a work machine, that's a big no-no.
After you run the command, try your Git command again. The error should be gone.
Cause #3: The repo was copied from Linux/Mac with different file permissions
Sometimes you copy a repo from a Linux or Mac machine to Windows, and the files carry over with ownership information that doesn't make sense in Windows. Git sees that weird ownership and throws the dubious ownership error.
The fix here is a bit more aggressive: copy the repo again, but make sure you remove the .git folder and reinitialize it. Or, if you don't need the history, just copy the files and run git init to start fresh.
But if you need the history, do this:
- Copy the repo to your Windows machine (if you haven't already).
- Open Git Bash or the terminal in the repo's root folder.
- Run this to remove the current
.gitfolder:
rm -rf .git
This is a destructive command—it wipes all your commit history. Only do this if you have the original repo elsewhere or you've pushed everything to a remote.
- Then initialize a new repo:
git init
Then add your remote and push if needed. That resets the ownership to your current user.
That's the nuclear option. Do it only if the first two fixes don't work and you're sure you have a backup.
Quick reference
| Cause | Fix | When to use |
|---|---|---|
| Folder owner mismatch | Change owner via Properties → Security → Advanced | Most common, do this first |
| Missing safe.directory | Run git config --global --add safe.directory <path> | Can't change owner or owner change didn't help |
| Ownership metadata from other OS | Delete .git and reinit | Last resort, only with backup |
Try the first fix. Most of the time that's all you need. If it doesn't work, move down the list. And remember, if you're on a company laptop, talk to your IT team before changing folder ownership—they might have a group policy that's causing this.