Mounting Folders as PSDrives
I’ve found a trick that makes working with multiple git repositories
a breeze! Did you know that powershell
has this nifty feature called a PSDrive
? It’s a low-level abstraction upon which things like Get-ChildItem
are built and it’s the power behind working with both directories/files as well as things like registries. With this feature, we can mount individual folders and expose them as if it is a full-fledged hard drive within our system.
For example, on my computer this blog’s repository is checked out to:
> C:\dev\blog
Therefore anytime I wanted to access it I would need to first remember where I put it and then cd:
into that directory
> cd C:\dev\blog
Could there be a better way? I think there is!
I opened my powershell
profile
code $profile
Then I added a new PSDrive
to alias my repository path
# Create a new "Blog:" drive pointing at the folder on my file system and don't write that process to the host
New-PSDrive -Name "Blog" -PSProvider "FileSystem" -Root "C:\dev\blog" | Out-Null
Now when I want to edit my blog the command is as simple as
> cd Blog:
… and the best part is that I don’t have to remember where I parked! And if I ever need to change it (or move in on a different computer), I can just update my alias and all my habits and muscle memory still work.
Leave a Comment