Google Drive and Git desktop.ini issue

Hey everyone, I’m new here and I’ve run into a problem with Git and Google Drive. I’m storing my Git repo on Google Drive and everything was fine until I tried to switch branches.

After making 5 commits on my master branch, I created a new branch from the 2nd commit. But when I try to go back to master, I get this error:

$ git checkout master
fatal: bad object refs/desktop.ini

I’ve tried deleting the desktop.ini file, but it didn’t help. I saw something about compressing the Git database, but I’m not sure what that means or how to do it.

I also tried running git gc, but got more errors:

$ 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

Has anyone dealt with this before? How can I fix it and get back to my master branch? Thanks for any help!

I’ve encountered a similar issue when Git repositories are stored on cloud services such as Google Drive. In my experience, the problem usually arises because of sync conflicts between Git and the cloud service. I solved it by first moving the repository out of Google Drive and then running diagnostic commands like git fsck to check for corruption and git reflog to review recent actions. If these steps don’t reveal the issue, you may need to manually recreate branches using commit hashes or clone a fresh copy from a remote repository. In the long term, using a dedicated Git hosting service like GitHub or GitLab can help avoid these kinds of problems.

I’ve dealt with similar issues when using Git with cloud storage. The problem likely stems from Google Drive creating desktop.ini files, which Git then tries to track. A potential solution is to add ‘desktop.ini’ to your .gitignore file. This prevents Git from tracking these system-generated files.

If that doesn’t work, try running ‘git config --system core.longpaths true’ to handle long file paths better. As a last resort, you might need to clone your repository fresh from a backup or remote source, then carefully merge your changes.

For future projects, I’d strongly recommend using a dedicated Git hosting service instead of cloud storage. It’ll save you headaches like this down the line.

had similar problems with dropbox. git and cloud storage don’t mix well. try moving ur repo to a local folder, then run git fsck --full to check for issues. if that fails, you might need to manually recreate branches using commit hashes. in future, use github or gitlab instead of google drive for git repos. less hassle!