#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

Fix 'Invalid Path' Error When Cloning GitHub Repo on Windows

koskila
Reading Time 9 min
Word Count 1455 words
Comments 0 comments
Rating n/a ( votes)
View

Let me open up with a few hot takes:

  • Operating System should be an enabler - infrastructure, that doesn't get in the way.
  • Version control should also be an enabler - and at best, a force multiplier.
  • Developers should be able to select their laptops so they'll stay as productive as possible.
  • Fun file names should be allowed.

Well, maybe nothing I said was really THAT hot of a take. But in my case, a developer - myself - choosing 2 different operating systems lead to fun file names that essentially disabled my version control. Things went haywire fast and hard.

Admittedly, some mistakes were made. And my primary mistake was to try to work on a repo on both a Windows machine and a mac.

Background

This is my first whole article written completely on the new site, with my new process for publishing. I'm not going to lie - I'm still trying to figure everything out with this static site generation thing - to get the scheduling to work more reliably than it does on WordPress (which isn't actually as difficult as I thought) and to get used to writing actual blog content using markdown!

I feel like every time I open my Windows laptop now, I run into a new fun issue! But that's probably mostly because I just have lost touch with my former favorite Operating System.

This time, the issue arose when I was working on a project on my Windows 11 laptop for a change, and tried to switch branches on a repository I had already cloned from GitHub earlier. One of my branches turned out to be inaccessible on Windows due to someone (me) committing in file names that only work on non-legacy operating systems (so everything but Windows).

But as usual, we'll take a step back, first. Let's see what was the error thrown.

Problem

So when changing your checked out branch in git on Windows - in my case, using GitHub Desktop, on Windows 11 - you suddenly run into the following error:

Invalid path error in git on Windows

Or in text form:

error: invalid path 'file/path.png?view-azure-devops
error: invalid path 'file/cabinet.png?view-azure-devops'

And this stops git from changing a branch at all. And it'll block a lot of other things, too - if you have file paths with question marks or other interesting things in them, for repositories and branches with those files, you will not be able to do the following things on Windows:

  • clone a repo with fun paths in the default branch
  • switch / check out a branch that has files with fun paths
  • fetch new commits from your current branch if it has gotten those files in a later commit

All in all, fun times!

Reason

The issue was actually a little bit more complex than yours truly just choosing to use the wrong Operating System.

I recognized the files - these were picture files migrated from my old blog on WordPress.

I mean - not that old, I JUST switched over - but still, the pictures had been there for months of years, with the weird url parameter in the file name. It worked on WordPress, running the migration scripts my macOS work machine handled the files just fine, and my build machines running Ubuntu built a website out of them just dandily.

That's also why I didn't realize there was an issue with the files in the first place. Because on mac OS there wasn't!

See, the issue happened because I had worked on this repository on a mac earlier.

Yep! I can already hear some of the more eager ones in the audience yelling something along the lines of "it's always Apple's fault!"

But Apple is not quite like DNS. Not as inevitable.

In this case, Apple is arguably doing the "normal" thing here - Android, iOS, macOS, Fedora, Ubuntu, Kubuntu, Lubuntu, Xubuntu, Ubuntu Cinnamon Remix, Budgie, Kali, Bodhi... Okay, you got me, like half of those are just flavors of Ubuntu, but still - everyone else handles weird URLs except for Windows (and Dropbox, to be fair, but maybe they run on Windows Servers?) so handling question marks and other weird stuff properly is arguably the norm - not the exception!

It's simple enough: Linux or macOS can handle all sorts of nonsense in file paths, Windows can not. Git can handle almost whatever you decide to throw at it - as long as it's a small file, that is, let's be sensible here.

Alright. So I used a script, got file names that worked on my mac, but when I tried to continue working on the project on my Windows laptop, it suddenly stopped working.

Solution

So I was faced with a decision: Do I solve this issue by ditching my Windows machine and get a cheap mac to replace it?

I already have the cheapest piece of Apple kit available (an M4 mac mini that absolutely sweeps the floor with my USD 4000 Windows laptop) so I could a cheap laptop to accompany it. Something modest - I mean, even a 36Gb 1Tb MacBook Pro with a M4 Max CPU will be cheaper than this laptop that hasn't proven to be that helpful.

Damn it, I'm getting really riled up about this laptop again. I think it'd be difficult to buy an Apple machine that would be worse value than this Dell brick! If I could return this pc I would, even though I wouldn't even get the money - my employer would.

Anyway. Let's actually find a way to fix it. And the only way to do it is that we'll need to get rid of invalid file names, obviously.

The problem with this issue is that you can't fix it on your Windows machine. You can not access the files with fun names, so you also can not rename them.

Not even on your dev drive (that's where I was trying to check the code out to) - nope, won't work!

But you're not out of luck. You're left with the following options - maybe some others as well, but these are the ones I had to choose between:

  1. Ditch the Dell and Make do with the Mac. This would be easy, if I had my Mac with me. But I don't.
  2. Pull the repository in WSL and rename the files. I don't know if WSL works on this machine and I have no idea how to use git from the command line, so I don't want to do this either.
  3. Ask the Copilot SWE Agent to rename the files for me, merge the PR, and update. I have had awful luck asking the agent to find and rename files so far, so I had no trust in its ability to rename 2 files - and I didn't want to wait.
  4. Rename the filenames in a Codespace on GitHub. This would've probably taken me a bit, but been otherwise feasible, but I chose to instead...
  5. Remove, download and rename the files using the GitHub web UI.

Yep, I chose the vibe coding way. That's what we do now.

So let's see how do we clean up these annoying files from our repository.

Step 1: Open GitHub and locate your files

You saw the names and paths of the files in the error message, so this should be easy. Open up your repository on GitHub and just browse all the way to the file(s) that have fun names.

Step 2: Download your fun files

Select the files, one-by-one, and hit "Download" (or "ctrl+shift+s") from the ellipsis menu.

This is kind of the trick - downloading the file will remove any illegal/fun characters from its name, and you'll end up with something like this instead:

alt text

Step 3: Remove the files from the repository using the GitHub UI

Did you know that you can actually just browse to the file on GitHub and remove it? As long as you are on the latest commit of the branch you've selected - and unless you've explicitly changed it, you should be!

Step 4: Rename and move the downloaded files

Nice! Now you can rename the files (in my case, I removed the fun part from the end) and move them back to your repository.

Remember to also fix any reference to said files!

... and with that, you should be good!


Is there some sort of magic remote git command that'll magically fix the file names? Maybe! But it would've taken me longer to figure out the command than it took me to go through this process, and this process worked just fine for me.

If you know about a better process, please do let me know!

Until next time I try to use Windows again!

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.

No comments yet.