OneDrive and Dev Projects: Keep .git, .venv and target Out of the Sync

A 10-second right-click led to OneDrive choking on .git, .venv and target folders. Links do not help. Here is what does, for Python, Rust and a Jekyll site.

TL;DR

  • The first right-click in File Explorer took about 10 seconds. The culprits: context-menu extensions, mostly PowerToys and OneDrive.
  • OneDrive was slow because my dev folders live in OneDrive, with .git, .venv, caches and target inside: thousands of small files that change all the time.
  • Symlinks and junctions do not help. OneDrive follows both and uploads what they point to. Tested.
  • What works: tell each tool where to write, outside OneDrive. No links at all.
  • OneDrive keeps backing up the source files, GitHub keeps the history. Belt and braces, minus the churn.
  • Result: first right-click down to ~1.5 s, OneDrive reports 0 symlinks and nothing pending.
Item How it is kept out of OneDrive
.git git init --separate-git-dir: the project only holds a small .git file
Python .venv UV_PROJECT_ENVIRONMENT, set per project by a small uv wrapper
.mypy_cache cache_dir in [tool.mypy] of pyproject.toml
.pytest_cache cache_dir in [tool.pytest.ini_options] of pyproject.toml
__pycache__ PYTHONPYCACHEPREFIX user environment variable
Rust target target-dir in .cargo/config.toml
TODO: Add a description
TODO: Add a legend

Table of Contents

Prerequisites

This was done and tested on the following configuration:

  • OS: Windows 11, PowerShell 7.
  • OneDrive: personal account, client 26.212, with Desktop, Documents and Pictures backed up to OneDrive.
  • Python: uv, mypy, pytest, VS Code.
  • Rust: cargo, rust-analyzer in VS Code.
  • Web site: Jekyll + Just the Docs, published by GitHub Actions (no local build).

My code lives in Documents, so in OneDrive. That is a choice, not an accident: I once lost a web site, and since then I want both OneDrive and GitHub. If your code is not in OneDrive, you do not need any of this.

The Symptom: a 10-Second Right-Click

The first right-click on a folder in File Explorer showed a busy cursor for almost 10 seconds. The second one was almost instant. Everything else on the machine was fine.

Describe the image here
I'm a legend

“Slow the first time, fast afterwards” is the signature of something being loaded once. In File Explorer, the usual suspect is a context-menu extension (a “shell extension”): third-party code that Explorer loads to build the menu. Each extension is asked what it wants to add. If one of them is slow (it talks to the network, to a sync service, wakes up a disk…), the whole menu waits.

The Investigation: Finding the Suspects

Restart Explorer to Reproduce the “First Time”

No need to reboot between tests. This kills Explorer, which restarts by itself, cold:

Stop-Process -Name explorer -Force

List the Classic Extensions

Classic context-menu handlers are registered under a few registry keys. This lists them with their DLL:

New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT -ErrorAction SilentlyContinue | Out-Null
$keys = '*','Directory','Folder','AllFilesystemObjects','Directory\Background','Drive'
$result = foreach ($k in $keys) {
    $path = "HKCR:\$k\shellex\ContextMenuHandlers"
    if (Test-Path -LiteralPath $path) {
        Get-ChildItem -LiteralPath $path | ForEach-Object {
            $clsid = $_.GetValue('')
            if (-not $clsid) { $clsid = $_.PSChildName }
            $dll = (Get-ItemProperty -LiteralPath "HKCR:\CLSID\$clsid\InprocServer32" -ErrorAction SilentlyContinue).'(default)'
            [pscustomobject]@{ Key = $k; Name = $_.PSChildName; Dll = $dll }
        }
    }
}
$result | Sort-Object Dll | Format-Table -AutoSize
Key                  Name                                   Dll
---                  ----                                   ---
AllFilesystemObjects {a2a9545d-a0c2-42b4-9708-a0b2badd77c8}
Folder               {a2a9545d-a0c2-42b4-9708-a0b2badd77c8}
*                    {a2a9545d-a0c2-42b4-9708-a0b2badd77c8}
*                    {90AA3A4E-1CBA-4233-B8BB-535773D48449}
Directory\Background  FileSyncEx                            C:\Program Files\Microsoft OneDrive\26.212.1029.0006\FileSyncShell64.dll
Directory             FileSyncEx                            C:\Program Files\Microsoft OneDrive\26.212.1029.0006\FileSyncShell64.dll
*                     FileSyncEx                            C:\Program Files\Microsoft OneDrive\26.212.1029.0006\FileSyncShell64.dll
Drive                FileLocksmithExt                       C:\Program Files\PowerToys\WinUI3Apps\PowerToys.FileLocksmithExt.dll
AllFilesystemObjects FileLocksmithExt                       C:\Program Files\PowerToys\WinUI3Apps\PowerToys.FileLocksmithExt.dll
Directory\Background PowerRenameExt                         C:\Program Files\PowerToys\WinUI3Apps\PowerToys.PowerRenameExt.dll
AllFilesystemObjects PowerRenameExt                         C:\Program Files\PowerToys\WinUI3Apps\PowerToys.PowerRenameExt.dll
Directory            EPP                                    C:\Program Files\Windows Defender\shellext.dll
*                    EPP                                    C:\Program Files\Windows Defender\shellext.dll
Drive                EPP                                    C:\Program Files\Windows Defender\shellext.dll
Folder               PintoStartScreen                       C:\Windows\System32\appresolver.dll
Folder               Offline Files                          C:\WINDOWS\System32\cscui.dll
Directory            Offline Files                          C:\WINDOWS\System32\cscui.dll
AllFilesystemObjects {474C98EE-CF3D-41f5-80E3-4AAB0AB04301} C:\WINDOWS\System32\cscui.dll
Directory\Background NvCplDesktopContext                    C:\WINDOWS\System32\DriverStore\FileRepository\nvlti.inf_amd64_88646ff9142f80fc\nv…
Drive                EnhancedStorageShell                   C:\Windows\System32\EhStorShell.dll
AllFilesystemObjects ModernSharing                          C:\WINDOWS\system32\ntshrui.dll
*                    Sharing                                C:\WINDOWS\system32\ntshrui.dll
Drive                Sharing                                C:\WINDOWS\system32\ntshrui.dll
Directory\Background Sharing                                C:\WINDOWS\system32\ntshrui.dll
Directory            Sharing                                C:\WINDOWS\system32\ntshrui.dll
Directory\Background New                                    C:\WINDOWS\system32\shell32.dll
AllFilesystemObjects CopyAsPathMenu                         C:\WINDOWS\system32\shell32.dll
AllFilesystemObjects SendTo                                 C:\WINDOWS\system32\shell32.dll
Folder               Library Location                       C:\WINDOWS\system32\shell32.dll
Directory            EncryptionMenu                         C:\WINDOWS\system32\shell32.dll
*                    Open With EncryptionMenu               C:\WINDOWS\system32\shell32.dll
*                    Open With                              C:\WINDOWS\system32\shell32.dll
Drive                {fbeb8a05-beee-4442-804e-409d6c4515e9} C:\WINDOWS\system32\shell32.dll
Directory            {596AB062-B4D2-4215-9F74-E9109B0A8153} C:\WINDOWS\system32\twext.dll
Drive                {596AB062-B4D2-4215-9F74-E9109B0A8153} C:\WINDOWS\system32\twext.dll
AllFilesystemObjects {596AB062-B4D2-4215-9F74-E9109B0A8153} C:\WINDOWS\system32\twext.dll
Directory            WorkFolders                            C:\Windows\System32\WorkfoldersShell.dll
Directory\Background WorkFolders                            C:\Windows\System32\WorkfoldersShell.dll
*                    WorkFolders                            C:\Windows\System32\WorkfoldersShell.dll
Drive                {D6791A63-E7E2-4fee-BF52-5DED8E86E9B8} C:\WINDOWS\system32\wpdshext.dll

Everything under C:\Windows\System32 is Windows itself. On my machine, only three third-party entries were left:

  • OneDrive: FileSyncShell64.dll
  • PowerToys: File Locksmith and PowerRename

List the “Modern” Extensions

The Windows 11 menu also gets entries from packaged apps (MSIX), declared in their manifest. They do not show up in the registry list above:

Get-AppxPackage | Where-Object { $_.InstallLocation } | ForEach-Object {
    $manifest = Join-Path $_.InstallLocation 'AppxManifest.xml'
    if ((Test-Path $manifest) -and (Select-String -Path $manifest -Pattern 'fileExplorerContextMenus' -Quiet)) {
        $_.Name
    }
}

Result: Photos, Notepad, Paint, Terminal, Office, three PowerToys packages and OneDrive (again).

Microsoft.Windows.Photos
Microsoft.PowerToys.FileLocksmithContextMenu
Microsoft.PowerToys.ImageResizerContextMenu
Microsoft.PowerToys.PowerRenameContextMenu
Microsoft.WindowsNotepad
Microsoft.WindowsTerminal
Microsoft.Paint
Microsoft.OneDriveSync
Microsoft.MicrosoftOfficeHub

Eliminate, One Suspect at a Time

  • Shift + right-click (classic menu directly): just as slow. So the classic extensions are involved, not only the new menu.
  • PowerToys: I turned off the modules I did not use (File Locksmith, PowerRename, Image Resizer, New+…). First right-click: ~3 s. PowerToys accounted for about 6 of the 10 seconds.
  • OneDrive: with OneDrive stopped, the first right-click was almost instant.
Describe the image here
I'm a legend

Stopping OneDrive does not unload its extension: the DLL stays in Explorer. When the OneDrive process is not there to answer, the extension may even wait for a timeout. Test with OneDrive running, then stopped, and compare.

Describe the image here
I'm a legend

File Locksmith (PowerToys) shows which process holds a file you cannot delete. Useful once a year. Its extension is loaded on every first right-click. If you need it, turn it on for five minutes in PowerToys, or use resmon (CPU tab, “Associated Handles”).

Why OneDrive?

To build the menu, the OneDrive extension asks the OneDrive process about the item: synced or not, local or online only. If OneDrive is busy, the answer is late, and the menu waits.

And OneDrive had plenty to be busy with. The folder I right-clicked was my web site repository. Its .git alone held 608 files, 231 MB. Around it, my Python and Rust projects had .git folders, virtual environments (one was 321 MB), mypy caches, Rust target folders… Thousands of small files that change at every commit, every build, every uv sync. Exactly what a sync client hates.

The Constraint: Keep the Backup

The easy answer would be “move your code out of OneDrive”. No. GitHub only has what was pushed. OneDrive has the working tree as it is, right now, including what I have not committed yet. I want and I need both.

What I want out of OneDrive is everything that is generated or churning: .git, .venv, caches, build output. The source files stay.

OneDrive itself cannot help here. With a personal account, there is no “do not sync this subfolder” option inside a backed-up folder like Documents. A folder-exclusion feature exists, but it is an admin policy for work and school accounts.

My first setup used symbolic links: in each Python project, .venv, .mypy_cache and .pytest_cache were links pointing to a folder outside OneDrive. It looked right. Explorer showed the link icons, the files were really on the other side.

Then I looked at onedrive.live.com. The content of those folders was there, online. Including a whole .venv created a week earlier.

So I tested it properly: a junction and a directory symlink inside OneDrive, each pointing to a folder outside, one file created before the link, one file after. Then a OneDrive restart to force a full rescan.

The test script: Test-OneDriveLinks.ps1. Run it again with -Cleanup to remove the links first, then the test folders.

Result: both files, behind both kinds of links, were online a few minutes later. Microsoft says it plainly in its Q&A: OneDrive syncs what the link points to, not the link itself.

Why did it look fine at first? OneDrive gets no change notifications from a folder outside OneDrive. Right after the link is created, nothing seems to happen, and the items stay “syncing” forever in Explorer. Then, at the next full rescan (a restart, for example), everything goes up.

Do not use symlinks or junctions to keep things out of OneDrive. And never delete such content from onedrive.live.com: OneDrive would carry the deletion back through the link and empty the target.

The Principle: Tell Each Tool Where to Write

Every tool that creates one of these folders has a setting for its location: an environment variable or a config file. No link, so nothing for OneDrive to follow.

I put everything in one root folder outside OneDrive, with an explicit name:

%USERPROFILE%\git_dirs_NEVER_TOUCH\
    README.md              rules, layout, repairs
    python\<project>\      .git, .venv, .mypy_cache, .pytest_cache
    python\_pycache\       all .pyc files
    rust\<path>\           .git, target
    40tude\.git            the web site repository
    _migration_backups\    git bundles and copies made before each migration

The name is a warning to my future self. This folder is backed up by nobody: OneDrive does not see it, and GitHub only has what was pushed. Everything in it can be rebuilt (uv sync, cargo build) except the .git folders.

The content of %USERPROFILE%\git_dirs_NEVER_TOUCH\ in File Explorer
The name is a warning to my future self

The Common Piece: .git Outside the Project

Git has an official way to keep the repository away from the working tree. Instead of a .git folder, the project holds a .git file with one line:

gitdir: C:/Users/<me>/git_dirs_NEVER_TOUCH/python/my_project/.git

Git reads it and goes there. It is the same mechanism as submodules, and VS Code handles it without any setting. git init creates this layout directly:

git init --separate-git-dir "$env:USERPROFILE\git_dirs_NEVER_TOUCH\python\my_project\.git"

git init --separate-git-dir does not create missing parent folders. Create ...\python\my_project first.

OneDrive now syncs a 56-byte file instead of hundreds of objects.

What if the Real .git Is Deleted?

Git stops with fatal: not a git repository: .... Nothing happens silently: no new empty repository, nothing pushed, nothing overwritten on GitHub. The source files are intact (they are in OneDrive). What is lost: commits never pushed, local branches never pushed, stashes.

Repair, from the project folder, VS Code closed:

Remove-Item .git -Force                               # the dangling pointer FILE only
git init -b main --separate-git-dir "$env:USERPROFILE\git_dirs_NEVER_TOUCH\python\my_project\.git"
git remote add origin https://github.com/<me>/my_project.git
git fetch origin
git reset origin/main                                 # mixed reset: working files untouched
git branch -u origin/main
git status

If you pile up 12,000 local commits without pushing and then wipe that folder “to free some space”, they are gone. Push often. Before deleting anything in git_dirs_NEVER_TOUCH:

git log --branches --not --remotes --oneline   # unpushed commits: must be empty
git stash list                                 # stashes: must be empty

The Python Case

A Python project split in two places: sources in OneDrive, .git, .venv and caches in git_dirs_NEVER_TOUCH, with the settings that point from one to the other
Where we are going: OneDrive keeps the sources, git_dirs_NEVER_TOUCH gets the heavy folders. The yellow items tell each tool where to write. Click on the image to zoom in.

Day to Day: Same Commands as Before

Before the details, here is what it looks like once everything is in place. I have an idea for a small project, my_hello:

  1. Go to my Python folder, in OneDrive.
  2. Create the project with New-PyProject.ps1 (more on it below) instead of uv init.
  3. Open it in VS Code.
  4. Work: add packages, run, test, commit, push.
cd "$env:OneDrive\Documents\Programmation\python"
./New-PyProject.ps1 my_hello -GitInit     # instead of "uv init my_hello"
cd my_hello
code .

uv add requests                           # the usual uv commands, unchanged
uv run my-hello
uv run pytest
uv run mypy src tests
git add .
git commit -m "feat: say hello"
git push                                  # often: .git is the only copy

Look at the commands after code .: this is the plain uv and git workflow, the one from the docs. Same commands, same habits. VS Code already uses the right interpreter, the terminal activates the right venv, uv run finds its environment. The only visible difference is the first command: a script instead of uv init. The rest happens behind my back. If I do not go and look in git_dirs_NEVER_TOUCH, I do not see it. And that is the whole point: OneDrive only sees the sources, and I do not have to think about it.

Under the hood, each tool is told to write in git_dirs_NEVER_TOUCH\python\<project folder name>\. One at a time.

__pycache__: one environment variable

Python creates a __pycache__ folder next to every imported module. A link cannot handle that (there is one per package folder). One user environment variable sends all .pyc files elsewhere:

[Environment]::SetEnvironmentVariable("PYTHONPYCACHEPREFIX", "$env:USERPROFILE\git_dirs_NEVER_TOUCH\python\_pycache", "User")

Then close every terminal and VS Code window. Running programs keep the old value.

.mypy_cache and .pytest_cache: pyproject.toml

Both tools accept a cache_dir, and both expand environment variables in it. With $USERPROFILE, my user name stays out of the files pushed to GitHub:

[tool.mypy]
cache_dir = "$USERPROFILE/git_dirs_NEVER_TOUCH/python/my_project/.mypy_cache"

[tool.pytest.ini_options]
cache_dir = "$USERPROFILE/git_dirs_NEVER_TOUCH/python/my_project/.pytest_cache"

For mypy, the docs only say that “some flags” support environment variable expansion. I checked the source: cache_dir goes through expand_path() (os.path.expandvars + expanduser).

.venv: the hard one

uv has no pyproject.toml setting for the location of the project environment. Only an environment variable, UV_PROJECT_ENVIRONMENT. An absolute path is used as-is, so one global value would make every project share (and overwrite) the same venv.

The answer: a small uv function in the PowerShell profile. For each call, it finds the project root (first folder with a pyproject.toml, walking up), and if that root is in OneDrive, points UV_PROJECT_ENVIRONMENT to git_dirs_NEVER_TOUCH\python\<project>\.venv. Then it calls the real uv.exe and restores the variable.

function uv {
    $venv = Get-UvOneDriveEnvPath          # $null outside OneDrive projects
    $previous = $env:UV_PROJECT_ENVIRONMENT
    try {
        if ($venv) { $env:UV_PROJECT_ENVIRONMENT = $venv }
        uv.exe @args
    }
    finally {
        $env:UV_PROJECT_ENVIRONMENT = $previous
    }
}

Full version, with the project root lookup and the install notes: UvOneDrive.ps1.

Loaded once from the profile:

Add-Content -Path $PROFILE -Value '. "$env:OneDrive\Documents\Programmation\python\UvOneDrive.ps1"'

The function only applies to uv typed in PowerShell. Anything that runs uv.exe directly (a bash shell, some VS Code tasks, other tools) creates a .venv inside the project. If one shows up, delete it.

VS Code finds the interpreter through .vscode/settings.json (machine-specific, so in .gitignore):

{
    "python.defaultInterpreterPath": "C:\\Users\\<me>\\git_dirs_NEVER_TOUCH\\python\\my_project\\.venv\\Scripts\\python.exe"
}

When VS Code opens a terminal, it activates that venv with a visible Activate.ps1 command. That is expected, and a good sign.

New Projects and Existing Ones

  • New-PyProject.ps1 creates a uv project with all of the above: uv init --vcs none, git init --separate-git-dir, the two cache_dir, .vscode/settings.json, and the first uv add with UV_PROJECT_ENVIRONMENT already set.
  • Move-PyProjectOutOfOneDrive.ps1 migrates an existing project: checks (git fsck), git bundle as a backup, removes .venv, caches and __pycache__ from the project (for a link: the link only), quits OneDrive, moves .git, writes the .git file, checks git sees it (rolls back if not), restarts OneDrive, adds the cache_dir, runs uv sync and pytest. -DryRun changes nothing and lists what would be done.

Download: New-PyProject.ps1, Move-PyProjectOutOfOneDrive.ps1.

Before deleting a .venv that lives inside a project, I compared its packages with uv.lock: 132 packages installed, all in the lock file. So uv sync rebuilds the exact same environment. If something was installed by hand with uv pip install, it would not come back.

On one project, the migration took a 321 MB .venv out of OneDrive.

The Rust Case

A Rust project split in two places: sources in OneDrive, .git and target in git_dirs_NEVER_TOUCH under the same relative path, pointed to by the .git file and .cargo/config.toml
Same idea for Rust: two pointers in the project (.git and .cargo/config.toml), the same relative path on both sides, and nothing to set on the PC.

Rust was already half right: my projects redirected target with target-dir in .cargo/config.toml. A config setting, not a link, so OneDrive never saw the build output. What was left: the .git folders, a few stray target folders, and one root for everything.

Day to Day: Same Commands as Before

Same exercise as for Python. I want to try something in a new project, my_hello, among my experiments:

  1. Go to the right subfolder of my Rust folder, in OneDrive.
  2. Create the project with New-RustProject.ps1 (more on it below) instead of cargo new.
  3. Open it in VS Code.
  4. Work: add crates, build, run, test, commit, push.
cd "$env:OneDrive\Documents\Programmation\rust\01_xp"
New-RustProject.ps1 my_hello 025_my_hello -GitInit   # instead of "cargo new 025_my_hello --name my_hello" (script on the PATH)
cd 025_my_hello
code .

cargo add anyhow                                     # the usual cargo commands, unchanged
cargo run
cargo test
cargo clippy
git add .
git commit -m "feat: say hello"
git push                                             # often: .git is the only copy

Why 025_my_hello and not just my_hello? I have been numbering my folders for a very, very long time, so the folder name and the crate name differ. A crate name cannot start with a digit, hence the two names, and the --name in the equivalent cargo new command. With a more classic layout, the first command is simply New-RustProject.ps1 my_hello.

Again, after code . this is the plain cargo and git workflow. cargo build writes to git_dirs_NEVER_TOUCH\rust\01_xp\025_my_hello\target, and nothing has to be set on the PC: the project carries its own .cargo\config.toml. The only new command is the first one.

Layout: Mirror the Relative Path

Rust projects are nested (01_xp\024_sha256, workspaces, step* sub-projects…), and folder names repeat. So the path relative to the rust folder is mirrored:

git_dirs_NEVER_TOUCH\rust\01_xp\024_sha256\
    .git\      precious
    target\    throwaway, "cargo build" recreates it
# .cargo/config.toml
[build]
target-dir = "C:/Users/<me>/git_dirs_NEVER_TOUCH/rust/01_xp/024_sha256/target"

Cargo reads .cargo/config.toml in the current folder and its parents. A config at the project root covers every sub-crate; a nested config with its own target-dir wins for its sub-tree. To check where cargo will write, without building anything:

cargo metadata --format-version 1 --no-deps | ConvertFrom-Json | Select-Object target_directory

.cargo/config.toml holds an absolute Windows path and is committed. The README of each project says so: on another machine, rename .cargo before building.

The rust-analyzer Leftovers

After migrating, a tiny target folder kept coming back inside projects, with only target\rust-analyzer\flycheck0\stdout and stderr. rust-analyzer writes its flycheck logs in <workspace>\target, ignoring target-dir (a known issue, see the Webliography). A few KB, harmless, already in .gitignore. The migration script recognizes this exact case and deletes it. Anything else named target that does not look like cargo output (CACHEDIR.TAG, .rustc_info.json) is kept: never delete a user folder because of its name.

New Projects and Existing Ones

  • New-RustProject.ps1: cargo new --vcs none, target-dir to the new location, and with -GitInit a separate git dir plus the first commit.
  • Move-RustProjectOutOfOneDrive.ps1: same steps as the Python one, plus rewriting target-dir in the root config (created if missing) and in every nested config that sets one, and a cargo metadata check (-Build also runs cargo build). A nested repository is reported and left alone: migrate it on its own.

Download: New-RustProject.ps1, Move-RustProjectOutOfOneDrive.ps1.

Tested on three layouts:

Project Layout What it tested
024_sha256 one crate a stray target in OneDrive, build to the new location
048_mono_to_distributed no root Cargo.toml, 10 sub-projects root config created, 16 nested configs rewritten
13_fraud_detection_5 workspace, 6 crates the whole workspace (sqlx included) builds outside

If you use the VS Code debugger with a launch.json pointing to ${workspaceFolder}/target/debug/..., it no longer finds the executable once target-dir is redirected. Fix the path, or let your debugger extension ask cargo where the binary is.

Adapting to Your Own Tools

The scripts of this post are written for my setup (Documents\Programmation\python and ...\rust, PowerShell 7, uv, cargo). Read them before running them, adapt the paths, and always start with -DryRun.

The recipe is always the same:

  1. Find the churning folders in your projects: build output, caches, dependencies, the repository.
  2. Find the tool’s own setting for each one: an environment variable or a config file. Read the docs, not a forum.
  3. Point it outside OneDrive, ideally with a path that does not hard-code your user name in committed files ($USERPROFILE where the tool expands variables).
  4. Check that the tool really writes there (most tools have a “show config” command), then check online that nothing goes up.
  5. No links. Ever.

A few leads to check against the docs of your version:

  • Node.js: node_modules cannot simply be moved; Node looks for it next to the code. I kept the two small ones of my web site in OneDrive (they barely change after npm ci).
  • .NET: BaseOutputPath and BaseIntermediateOutputPath in a Directory.Build.props move bin and obj.
  • CMake: build out of source (cmake -B <dir>) with <dir> outside OneDrive.
  • Jekyll: destination and cache_dir in _config.yml, if you build locally.
  • Any tool: if the only way to move a folder is a link, the tool is not on your side. Keep the folder small, or keep the project out of OneDrive.

The Web Site: One Repository, Done by Hand

The web site repository split in two places: the site sources in OneDrive, its .git folder in git_dirs_NEVER_TOUCH
The web site: a single pointer (.git), nothing to set on the PC, no local build.

The site you are reading is a single repository: Markdown, Jekyll, published by GitHub Actions. No local build, so no _site or .jekyll-cache. The only big thing was .git: 233 MB, 608 files.

It is also the repository I care most about. So no script: one command at a time, with a check after each step.

  1. Close everything that touches the site: VS Code, GitKraken, terminals.
  2. Check: git status, git branch -vv, nothing unpushed, no stash, git fsck --full.
  3. Double backup, OneDrive still running (it must be able to read every file):
$backup = "$env:USERPROFILE\git_dirs_NEVER_TOUCH\_migration_backups"
$stamp  = Get-Date -Format "yyyyMMdd-HHmmss"
New-Item -ItemType Directory -Path $backup -Force | Out-Null
git bundle create "$backup\site-$stamp.bundle" --all
git bundle verify --quiet "$backup\site-$stamp.bundle"
robocopy .git "$backup\site-$stamp.git-copy" /E /COPY:DAT /R:1 /W:1 /NFL /NDL /NP

The bundle only holds branches and tags. The full copy also keeps the config, the reflog, the GitKraken settings, and one dangling commit git fsck had reported. Same file count on both sides: 608 = 608.

  1. Quit OneDrive and check it is really gone (Get-Process OneDrive prints nothing).
  2. Move .git and write the pointer file:
$newGitDir = "$env:USERPROFILE\git_dirs_NEVER_TOUCH\40tude\.git"
Move-Item -LiteralPath .\.git -Destination $newGitDir -Force
[IO.File]::WriteAllText((Join-Path (Get-Location) ".git"), "gitdir: " + ($newGitDir -replace '\\', '/') + "`n")
(Get-Item .\.git -Force).Attributes = 'Hidden, Archive'
  1. Compare with step 2: same branches, same last commit, same git status. The pre-commit hook is in the site itself (core.hooksPath = tools/hooks, a relative path), so it is not affected.
  2. Restart OneDrive, then a real commit and push to prove the hook still runs.

On onedrive.live.com, .git is now a 56-byte file.

[IO.File]::WriteAllText with a relative path writes relative to the .NET current directory, which is not PowerShell’s current location. Always pass a full path, hence the Join-Path (Get-Location).

Results, and Watching OneDrive From the Command Line

The first right-click, in the worst case (Explorer just restarted, OneDrive folder): about 1.5 to 2 seconds, down from almost 10.

I do not fully trust the OneDrive tray icon, so I wanted the state from the command line. There is no official cmdlet. Three things work:

1. SyncDiagnostics.log, the only OneDrive log in plain text. It is a snapshot of the current state, not a history:

$diag = "$env:LOCALAPPDATA\Microsoft\OneDrive\logs\Personal\SyncDiagnostics.log"
(Get-Item $diag).LastWriteTime
Get-Content $diag -TotalCount 80

After the migrations: FilesToUpload = 0, ChangesToProcess = 0, ChangesToSend = 0 and SymLinkCount = 0. No more links in sight.

2. The process itself (works on a non-English Windows, unlike Get-Counter):

Get-CimInstance Win32_PerfFormattedData_PerfProc_Process -Filter "Name LIKE 'OneDrive%'" |
    Select-Object Name, PercentProcessorTime, IOReadBytesPersec, IOWriteBytesPersec

PercentProcessorTime adds up all the cores. On a 20-thread CPU, 36 % here means about 1.8 % of the machine, which is what Task Manager shows.

3. Its network connections:

(Get-NetTCPConnection -OwningProcess (Get-Process OneDrive).Id -State Established -ErrorAction SilentlyContinue).Count

CPU near 0 and no disk activity for a minute: OneDrive is done.

Conclusion

  • A slow right-click was the visible end of a bigger problem: OneDrive watching thousands of files it should never have seen.
  • Links are not the answer. OneDrive follows symlinks and junctions.
  • Each tool’s own setting is. .git file, UV_PROJECT_ENVIRONMENT, cache_dir, PYTHONPYCACHEPREFIX, target-dir.
  • OneDrive keeps the sources, GitHub the history, and one clearly named folder holds the rest. Only its .git folders matter: push often.
  • Migrate a project before working on it again. Not all at once.
  • And keep the old backups a month, just in case.

Webliography


Back to top

Published on: Nov 28 2026 at 11:23 PM | Last updated: Nov 30 2026 at 04:55 PM

Copyright © 1964-2026 - 40tude