Robert Westerlund

A developer's blog on code, technology and tools in the Web, .NET and other development areas.


Working with Git on remote computer using a PSDrive

I have a web site which I update using a git repository. I make my changes, push the changes to a git service provider (e.g. GitHub) and then pull the latest version on the server. However, I don't want to have it automatically pull any changes, but I want to manually trigger a pull at the times I want the site to update.

I wanted to avoid Remote Desktop and also wanted to stay in my favorite console; the PowerShell console. I couldn't do it by using ordinary PowerShell remoting, since the git pull will ask me for username and password, which won't work via a PowerShell session. What I ended up doing was setting up a server share (this could be the root admin share, if wanted) as a PSDrive and then run my git command from the PSDrive.

PS C:\> New-PSDrive -Name MyWebServer -PSProvider FileSystem -Root \\WebServer01\MyGitRootShare -Credential (Get-Credential MYDOMAIN\MyUserName)
PS C:\> cd MyWebServer:
PS MyWebServer:\>git pull origin master
Username for '': MyUserName
Password for '':

Using a PSDrive (mapped network drive) PowerShell was perfectly fine displaying the interactive prompt from Git, since it was executing git locally and not via remoting.

Git seemed slower working via a PSDrive than working locally, but that was expected and the difference wasn't noticable enough for me to care.