How to fix error: unable to create file: OneDrive folder synchronization conflict in Git

GitINTERMEDIATEMEDIUMUpdated Dec 6, 2025· 357 views

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.

Quick fix

Fixes error: unable to create file: OneDrive folder synchronization conflict

# Example: Move from OneDrive Documents to a local folder
Move-Item -Path "$env:USERPROFILE\OneDrive\Documents\my-project" -Destination "C:\Projects\my-project"
  1. Move the repository outside OneDrive
  2. Pause OneDrive sync during Git operations
  3. Delete OneDrive conflict copies
  4. Exclude .git folder using Group Policy (Windows Pro/Enterprise)
git — error
# Example: Move from OneDrive Documents to a local folder
Move-Item -Path "$env:USERPROFILE\OneDrive\Documents\my-project" -Destination "C:\Projects\my-project"
error: unable to create file: OneDrive folder synchronization conflict

What this error means

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.

Typical symptoms

  • Git commands fail with 'error: unable to create file' mentioning OneDrive or sync conflicts
  • Duplicate files appear in the .git directory with your computer name appended
  • OneDrive shows 'Looking for changes' indefinitely and stops syncing other files
  • Git operations that worked before suddenly fail after enabling OneDrive sync
  • FETCH_HEAD, index, or other .git files have conflict copies
  • VS Code or other IDEs show the option to 'Initialize Repository' on an existing repo
  • Git reports fatal errors about corrupted or missing objects in the repository
  • OneDrive notification shows sync errors or conflicts for files in your repository

Common causes

  1. Git repository is located inside a OneDrive-synced folder (Documents, Desktop, or custom sync folder)
  2. OneDrive cannot keep up with Git's rapid file updates during fetch, pull, or checkout
  3. OneDrive locks files for syncing while Git tries to write to them
  4. OneDrive creates conflict copies when files change faster than it can sync
  5. Windows file locking prevents Git from modifying files OneDrive is reading
  6. OneDrive's 'Files On-Demand' feature interferes with Git accessing placeholder files
  7. A Windows update changed OneDrive's sync behavior or corrupted existing repositories
  8. Multiple devices syncing the same repository cause additional conflicts

How to fix "error: unable to create file: OneDrive folder synchronization conflict"

1Move the repository outside OneDrive

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:

powershell
# 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:

bash
cd /c/Projects/my-project
git status

Recommended folder structure:

bash
C:\
├── Projects\              # Your Git repositories (not synced)
│   ├── project-a\
│   └── project-b\
└── Users\YourName\
    └── OneDrive\         # Synced folder (no Git repos here)
        └── Documents\
2Pause OneDrive sync during Git operations

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:

bash
git fetch origin
git pull origin main
git checkout feature-branch

Resume OneDrive:
1. Click the OneDrive icon again
2. Click "Resume syncing"

Using PowerShell to pause/resume:

powershell
# 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.

3Delete OneDrive conflict copies

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:

powershell
# 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:

bash
# Find files with typical conflict patterns
find .git -name "*-*" -type f | grep -E "-(PC|DESKTOP|LAPTOP)"

Delete the conflict copies:

powershell
# 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-Item

After deleting conflicts, verify repository integrity:

bash
git fsck
git status

If Git reports errors, you may need to re-clone the repository.

4Exclude .git folder using Group Policy (Windows Pro/Enterprise)

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.

5Use 'Always keep on this device' for the .git folder

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:

powershell
# Show OneDrive status for files in .git
attrib .git\*

Look for the O attribute (offline/cloud-only) or P (pinned/always available).

6Re-clone the repository if corrupted

If OneDrive sync has corrupted your repository beyond repair, the safest option is to re-clone:

Step 1: Backup any uncommitted changes

bash
# 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.patch

Step 2: Move or delete the corrupted repository

powershell
# Rename the old folder
Rename-Item -Path "my-project" -NewName "my-project-corrupted"

Step 3: Clone fresh to a non-OneDrive location

bash
cd /c/Projects
git clone https://github.com/username/my-project.git
cd my-project

Step 4: Apply your saved changes (if any)

bash
# If you saved a patch
git apply ~/my-changes.patch

# Or manually copy files from the backup

Step 5: Delete the corrupted folder
Once you've verified the new clone works and your changes are restored:

powershell
Remove-Item -Path "my-project-corrupted" -Recurse -Force
7Use symbolic links to separate working files from .git

An 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:

bash
# 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:

bash
# 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 status

Directory structure:

bash
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.

Advanced notes

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:

bash
# 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/main

For 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.

Frequently asked questions

What does "error: unable to create file: OneDrive folder synchronization conflict" mean?
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. git directory and working tree.
How do I fix "error: unable to create file: OneDrive folder synchronization conflict"?
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.
What causes "error: unable to create file: OneDrive folder synchronization conflict"?
Git repository is located inside a OneDrive-synced folder (Documents, Desktop, or custom sync folder) OneDrive cannot keep up with Git's rapid file updates during fetch, pull, or checkout OneDrive locks files for syncing while Git tries to write to them
Is the "error: unable to create file: OneDrive folder synchronization conflict" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading