Contents
data/authors/Paul Logan.json

Creating a new Git Repo with SSH credentials for the first time

I am using VS Code to develop a new PWA - Visual Studio seemed like overkill for what would be a handful of files. I also didn’t see the need for a solution and/or a project file, which would be necessary in Visual Studio.

Create the Repo - The right way

  • Log into your GitHub account and create the repository.
  • Copy the SSH path for the new repo
  • Open VS Code and choose “Clone Git Repository”, pasting in the path from the step above into the URL input that is displayed.

Create the Repo - Old way

Log into your GitHub account and create the repository - I could not find a straightforward way to create a brand new repository from the command line.

Set up the application folder

I create the app’s root folder on my computer, right click the folder and Open with Code:

Opening folder in VS Code
Opening folder in VS Code

Press Ctrl and ' to call up the VS Code Terminal and we can begin connecting the local folder to the git repo:

Accessing the VS Code Terminal
Accessing the VS Code Terminal

Connecting local app folder to Git Repo

I execute the following commands in the terminal:

Steps 2 and 3 set a custom git config for this project, using my personal GitHub account details. I have two Git accounts from two providers - GitHub for my personal repos and Azure for my work repos.

I have two Git accounts from two providers - GitHub for my personal repos and Azure for my work repos. As my work Git account is the default on my computer, I need to change them for this demo version of the app. The second and third steps set a custom git config for this project, using my personal GitHub account details.

Initialising the PWA inside VS Code
Initialising the PWA in VS Code

I added the first web page file to the folder and then performed

  • git add . to track the untracked welcome.html file. Then git push, but because this is a brand new repo, I got the following error:

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream origin master

So, I performed the recommended command above and moved onto the next error:

error: src refspec master does not match any error: failed to push some refs to ‘github.com:yourUserName/PWA-4-Blog.git’

Stackoverflow informed me that for me, the cause of the error was:

“there is nothing committed on master branch yet. Be sure, that you have staged your changes using the git add command and committed them using the git commit command before pushing them to the remote.”

So I executed

  • git commit -m “Initial landing page for PWA added” and re-tried the recommended git push.
Logon failed, use ctrl+c to cancel basic credential prompt.
Errors trying to push first commit
Errors trying to push first commit

I had previously been using password authentication for my personal GitHub, but as per the announcement, this was no longer an option

A quick read of the SSH guidelines on GitHub and I start the process of setting up an SSH connection.

Create an SSH key

  • Windows Terminal
  • ssh-keygen -t rsa -b 4096 -C “YOUR_GITHUB_EMAIL_ADDRESS” (not just ssh-keygen, which defaulted to my_name@computer_name as the comment)
  • Enter passphrase (and save the passphrase in your password manager entry for GitHub)
  • Copy generated public key into GitHub SSH settings
Generating ssh key
Generating ssh key

Configure SSH-Agent

SSH-Agent and OpenSSH “are tools in Windows that can be used to authenticate to remote Git repositories, such as GitLab, GitHub, Azure DevOps, etc. Once set up as a service that stores your various SSH keys, this can facilitate authentication without entering a password each time, removing the irritation of entering a password every time you wish to push/pull/etc. from a Git repository.”

Install, configure to auto-start upon login and manually start the service with the following PowerShell commands run from an elevated terminal window:

  • Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service
  • start-ssh-agent.cmd

I was asked to enter the passphrase for the SSH key I had previously created:

Install ssh agent service
Install ssh agent service

I had to re-create the SSH key afterwards, so I needed to use the following command to add it manually to the agent:

  • ssh-add .ssh\id_rsa
Adding SSH key to agent
Adding SSH key to agent