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:
Press Ctrl and ' to call up the VS Code Terminal and we can begin connecting the local folder to the git repo:
Connecting local app folder to Git Repo
I execute the following commands in the terminal:
- git init command to initialise an empty git repository
- git config user.name curlybapchap
- git config user.email curlybapchap@hotmail.com
- git remote add origin https://github.com/curlybapchap/PWA-4-Blog.git
- git remote add origin git@github.com:curlybapchap/PWA-4-Blog.git
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.
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:
Stackoverflow informed me that for me, the cause of the error was:
So I executed
- git commit -m “Initial landing page for PWA added” and re-tried the recommended git push.
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
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:
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