This error occurs when Git operations conflict with OneDrive's file synchronization on Windows. OneDrive creates duplicate files or blocks access when Git rapidly updates files during operations like fetch, pull, or checkout. The solution involves either moving repositories outside OneDrive or configuring sync settings to prevent conflicts.
The "unable to create file: OneDrive folder synchronization conflict" error occurs when you have a Git repository located inside a folder that OneDrive is actively synchronizing. This creates a fundamental conflict between how Git and OneDrive handle file changes. When Git performs operations like `git fetch`, `git pull`, `git checkout`, or `git merge`, it rapidly updates many files in the `.git` directory and working tree. Git might update files dozens or hundreds of times in quick succession (once for every branch, commit object, or file). OneDrive detects these changes and tries to sync them to the cloud, but before the upload completes, Git overwrites the file again. OneDrive interprets this as a conflict and responds by either: - Creating duplicate "conflict" files with the computer name appended (e.g., `FETCH_HEAD-PCName.txt`) - Blocking Git from writing to files that are "in use" by the sync process - Corrupting the `.git` directory by partially syncing files This is a known incompatibility between Git's rapid file operations and cloud sync clients. The same issue can occur with Google Drive, Dropbox, and other sync services, but OneDrive on Windows is particularly problematic due to its deep integration with the operating system.
The most reliable solution is to move your Git repository to a location that OneDrive doesn't sync. This eliminates the conflict entirely.
Step 1: Close applications using the repository
Close VS Code, your IDE, and any terminals open in the repository.
Step 2: Move the repository folder
Move your project folder to a non-synced location:
# Example: Move from OneDrive Documents to a local folder
Move-Item -Path "$env:USERPROFILE\OneDrive\Documents\my-project" -Destination "C:\Projects\my-project"Or use File Explorer to drag the folder to a new location like:
- C:\Projects\
- C:\Users\YourName\Projects\ (outside OneDrive)
- D:\Code\ (different drive)
Step 3: Update your terminal/IDE to use the new path
Open a new terminal and navigate to the new location:
cd /c/Projects/my-project
git statusRecommended folder structure:
C:\
├── Projects\ # Your Git repositories (not synced)
│ ├── project-a\
│ └── project-b\
└── Users\YourName\
└── OneDrive\ # Synced folder (no Git repos here)
└── Documents\If you must keep the repository in a OneDrive folder temporarily, pause syncing before running Git commands:
Pause OneDrive:
1. Click the OneDrive cloud icon in the system tray (bottom-right)
2. Click the gear icon (Settings)
3. Select "Pause syncing" → Choose 2 hours, 8 hours, or 24 hours
Run your Git commands:
git fetch origin
git pull origin main
git checkout feature-branchResume OneDrive:
1. Click the OneDrive icon again
2. Click "Resume syncing"
Using PowerShell to pause/resume:
# Note: There's no official CLI to pause OneDrive
# But you can stop the process temporarily
Stop-Process -Name "OneDrive" -Force
# Run your Git operations here
# Restart OneDrive
Start-Process "$env:LOCALAPPDATA\Microsoft\OneDrive\OneDrive.exe"Important: This is a workaround, not a permanent solution. Every time you forget to pause, you risk conflicts.
OneDrive creates conflict copies with your computer name appended. These are generally outdated duplicates that can be safely deleted.
Find conflict files in .git directory:
# List all conflict files
Get-ChildItem -Path ".git" -Recurse -Filter "*-*" | Where-Object { $_.Name -match "-[A-Za-z0-9]+\." }
# Or search by your computer name
Get-ChildItem -Path ".git" -Recurse | Where-Object { $_.Name -like "*-$env:COMPUTERNAME*" }In Git Bash:
# Find files with typical conflict patterns
find .git -name "*-*" -type f | grep -E "-(PC|DESKTOP|LAPTOP)"Delete the conflict copies:
# Preview what will be deleted
Get-ChildItem -Path ".git" -Recurse | Where-Object { $_.Name -like "*-$env:COMPUTERNAME*" }
# Delete them (be careful!)
Get-ChildItem -Path ".git" -Recurse | Where-Object { $_.Name -like "*-$env:COMPUTERNAME*" } | Remove-ItemAfter deleting conflicts, verify repository integrity:
git fsck
git statusIf Git reports errors, you may need to re-clone the repository.
If you have Windows Pro or Enterprise, you can configure OneDrive to exclude certain file types or folders:
Using Group Policy Editor:
1. Press Win + R, type gpedit.msc, and press Enter
2. Navigate to: Computer Configuration → Administrative Templates → OneDrive
3. Find "Exclude specific kinds of files from being uploaded"
4. Enable it and add file extensions or patterns
Note: The Group Policy Editor cannot exclude specific folder names like .git directly, but you can exclude certain file types common in Git:
- *.pack
- *.idx
- *.lock
Registry alternative (all Windows versions):
Unfortunately, there's no registry key or native OneDrive feature to exclude folders by name like .gitignore works for Git.
Windows Pro only: If gpedit.msc is not available, you're on Windows Home and this option won't work. Consider the other solutions instead.
OneDrive's "Files On-Demand" feature can cause issues when Git tries to access files that exist only as placeholders in the cloud. Forcing the .git folder to stay local may help:
Make .git folder always available:
1. Open File Explorer and navigate to your repository
2. Right-click the .git folder
3. Select "Always keep on this device"
This downloads all files in .git and keeps them local, which may reduce some conflicts.
Important limitations:
- This doesn't prevent OneDrive from syncing changes TO the cloud
- It only ensures files are always downloaded FROM the cloud
- You'll still experience sync conflicts during Git operations
Check current sync status:
# Show OneDrive status for files in .git
attrib .git\*Look for the O attribute (offline/cloud-only) or P (pinned/always available).
If OneDrive sync has corrupted your repository beyond repair, the safest option is to re-clone:
Step 1: Backup any uncommitted changes
# Check for uncommitted work
git status
git stash list
# If you have changes, copy modified files manually
# or try to create a patch (may fail if repo is corrupted)
git diff > ~/my-changes.patchStep 2: Move or delete the corrupted repository
# Rename the old folder
Rename-Item -Path "my-project" -NewName "my-project-corrupted"Step 3: Clone fresh to a non-OneDrive location
cd /c/Projects
git clone https://github.com/username/my-project.git
cd my-projectStep 4: Apply your saved changes (if any)
# If you saved a patch
git apply ~/my-changes.patch
# Or manually copy files from the backupStep 5: Delete the corrupted folder
Once you've verified the new clone works and your changes are restored:
Remove-Item -Path "my-project-corrupted" -Recurse -ForceAn advanced workaround is to keep your working files in OneDrive while storing the .git directory elsewhere using --separate-git-dir:
Clone with separate git directory:
# Keep working files in OneDrive, but .git folder elsewhere
git clone --separate-git-dir="C:/GitRepos/my-project.git" \
https://github.com/username/my-project.git \
"$HOME/OneDrive/Documents/my-project"For an existing repository:
# Move .git to a non-synced location
mv .git /c/GitRepos/my-project.git
# Create a .git file pointing to the real location
echo "gitdir: C:/GitRepos/my-project.git" > .git
# Verify it works
git statusDirectory structure:
C:\GitRepos\ # Not synced by OneDrive
└── my-project.git\ # The actual .git directory
├── objects\
├── refs\
└── ...
C:\Users\YourName\OneDrive\Documents\
└── my-project\ # Synced by OneDrive
├── .git # File containing: gitdir: C:/GitRepos/my-project.git
├── src\
└── ...This way, your source code syncs to OneDrive for backup, but Git's internal files don't cause sync conflicts.
Why OneDrive and Git Don't Mix Well:
Git was designed for local filesystems with POSIX-like semantics. It expects:
1. Atomic file operations (rename completes instantly)
2. No external processes modifying files during operations
3. Consistent file state across reads
Cloud sync clients like OneDrive violate these assumptions by:
- Reading files while Git is writing them
- Creating "conflict copies" instead of failing gracefully
- Holding file locks during upload/download
- Using placeholder files (Files On-Demand) that may not contain actual data
The Technical Conflict:
When you run git fetch, Git:
1. Downloads new objects (potentially hundreds of files)
2. Updates refs (branch pointers)
3. Writes to FETCH_HEAD, HEAD, config, and other files
4. May update the index
Each file update triggers OneDrive to:
1. Detect the file change
2. Read the file for upload
3. Lock the file briefly
4. Queue the upload
If Git updates a file before OneDrive finishes reading it, OneDrive sees this as a conflict and creates a copy with your computer name appended.
Similar Issues with Other Sync Clients:
This isn't unique to OneDrive:
- Google Drive - Same rapid-change detection issues
- Dropbox - Slightly better with its smart sync, but still problematic
- iCloud Drive - Similar issues on macOS
- Box Drive - Same fundamental conflict
The recommendation from Git experts: Don't put Git repositories in cloud-synced folders.
If You Must Use Cloud Backup for Repositories:
Consider these alternatives:
- Use remote Git hosting (GitHub, GitLab, Bitbucket) - This is what Git is designed for
- Use Git bundle for offline backup: git bundle create repo.bundle --all
- Use a backup tool that understands Git (like gitbackup or rclone)
- Sync only when the repository is "at rest" (closed, not in use)
Recovering from OneDrive Corruption:
If your repository is corrupted:
# Check repository health
git fsck --full
# Try to recover
git reflog # See recent actions
git reset --hard HEAD~1 # Go back one commit if needed
# If objects are corrupted, re-fetch from remote
git fetch origin
git reset --hard origin/mainFor Organizations:
If your organization mandates OneDrive for all documents:
1. Request an exception for development folders
2. Use C:\Dev or similar outside the user profile
3. Document the incompatibility for IT policy review
4. Consider network drives with proper caching instead
Windows-Specific File Locking:
Windows uses mandatory file locking, meaning a process can lock a file and prevent others from accessing it. OneDrive uses these locks during sync. Unix-like systems use advisory locks that Git can work around.
This is why the same repository might work fine on macOS or Linux with cloud sync clients but fail on Windows.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git