Every morning I come into work and execute a couple of git commands to bring me up to date with my team. They are as follows:
git remote update
git merge main/master
I use PowerShell as my go-to command line tool, and whenever I enter the first command (git remote update
) I get a prompt asking me for my SSH key passphrase:
Enter passphrase for key '/c/Users/myUsername/.ssh/id_rsa':
Usually I would just go ahead and enter this, but I am looking to automate the process using a PowerShell script. What I've done is put my passphrase into a .txt file (not the most secure, but I can address on that once the pipeline works) and I pull it out every time I run the script. But I can't see a way to pass it to the command? Here is my code:
Set-Location C:\path\to\repo
$pass = Get-Content C:\path\to\passphrase.txt -First 1
git remote update
git merge main/master
I expected that once git remote update
ran it would prompt me for the passphrase as usual before continuing, and planned to build from there, but it didn't. It just fails with a git error:
git : Permission denied, please try again.
At line:3 char:1
+ git remote update
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Permission denied, please try again.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
Permission denied, please try again.
Permission denied (publickey,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
How can I pass my passphrase $pass
to the git remote update
command?