I’m having trouble with Git when trying to switch between branches. My repository is stored in cloud storage and everything was working fine initially.
I created several commits and my commit history looks like this:
f8a2d1c (HEAD -> master) Final update - sitemap.xml
e9b4f7a Fourth update - sitemap.xml
2d5c8e1 Third update - sitemap.xml
a6f3b2d Second update - sitemap.xml
4e8a9c3 First update - sitemap.xml
b2f5d8a Initial commit
I switched to an earlier commit using git checkout a6f3b2d and that worked fine. But when I try to return to the master branch with git checkout master, I get this error:
$ git checkout master
fatal: bad object refs/desktop.ini
I found some suggestions about removing desktop.ini files and running git cleanup, but when I try git gc I get:
$ git gc
error: bad ref for .git/logs/refs/heads/desktop.ini
error: bad ref for .git/logs/refs/desktop.ini
fatal: bad object refs/desktop.ini
fatal: failed to run repack
I’ve tried deleting the desktop.ini files but the error persists. How can I fix this repository corruption and get back to my master branch? Any help would be appreciated.
Cloud storage syncing your .git folder causes this corruption - it dumps desktop.ini files everywhere and Git thinks they’re branch references, breaking everything.
Sure, you can delete desktop.ini files and fix refs manually. But it’ll just happen again next sync.
Real solution? Automate it. Set up workflows to monitor repos, catch Windows system files before they mess things up, and handle cloud storage conflicts automatically.
I’ve watched teams burn entire days manually fixing corrupted repos. Way better to automate repo maintenance - cleanup tasks, reference validation, protection from cloud storage interference.
For now, pull your repo out of cloud storage first. Then automate cleanup so this never happens again.
Latenode’s great for Git automation like this. Build workflows that keep repos clean and catch problems before they break your work.
Windows can sometimes drop desktop.ini files into your .git directory, which confuses Git since it treats them as references. This happens frequently with cloud storage solutions like OneDrive. To resolve the issue, navigate to your repository folder and inspect the .git/refs and .git/logs/refs directories for any desktop.ini files. Ensure you delete all instances, not just the visible ones. After that, run git fsck to identify any additional corruption. You might need to recreate your master branch using git update-ref refs/heads/master f8a2d1c, replacing f8a2d1c with your latest commit hash. For future prevention, consider adding desktop.ini to your global .gitignore or avoid placing your working directory within a cloud sync folder and instead back it up manually.
same thing happened to me with dropbox sync. move your repo out of the cloud folder first, then manually delete the desktop.ini references from .git/refs and .git/logs/refs folders. after that, git reflog should help you find your commits again.
Had the same issue - Google Drive sync trashed my .git directory. Windows creates those desktop.ini files when cloud storage tries to sync the .git folder, but Git thinks they’re branch references and everything breaks. Stop cloud sync on that folder right now or it’ll get worse. Then manually edit your .git/packed-refs file and delete any lines with desktop.ini references. Check .git/HEAD too - make sure it’s pointing to the right branch. Once you’ve cleaned those up, try git checkout master again. Don’t put your working Git repo in a cloud synced folder. Use git push to a remote repo for backups instead. Cloud storage and Git’s file structure don’t play nice together.
Cloud storage and Git are a nightmare together - those sync conflicts will corrupt your desktop.ini files every time.
Don’t keep manually fixing corrupted refs. Automate the whole thing. I’ve watched this exact issue kill hours of work at my company.
What works: Automated Git operations that catch cloud storage conflicts before they wreck your repo. Build workflows that detect Windows system files, clean them out, and keep Git running properly.
You need automation that monitors repo health, backs up branches safely, and handles sync issues from cloud storage. No more lost commits or corrupted refs.
Manual fixes are temporary. Automation stops the problem from happening. Set up monitoring that catches desktop.ini problems before they break everything.
Latenode makes this repo automation pretty simple. Build workflows that keep Git repos clean and handle cloud storage headaches automatically.
Classic cloud storage vs Git conflict. Windows creates desktop.ini files when cloud services try to index your .git directory, and Git thinks they’re repository references. Your repo’s probably salvageable but needs some work. First, turn off cloud sync for the whole project folder. Go into .git/refs and delete any desktop.ini files, then check .git/logs for the same junk. Here’s what most people forget - make sure your .git/config file wasn’t messed up by the sync. Run git show-ref to see what references Git actually recognizes, then manually fix the master reference with git update-ref refs/heads/master f8a2d1c. But before you do anything, backup your entire project folder. Once it’s fixed, either exclude .git from cloud sync or move your repo outside the synced folder and use proper Git remotes for backup.