Tutorial on updating website using Git over SSH
In a previous tutorial, we updated a webpage on GitHub Pages by using Git over https. In this tutorial, we will update the same website using Git over SSH. This requires that we generate an public SSH key on our local machine (as was shown in tutorial here).
Then we have to provide our public SSH key to our webhost provider, which for the purpose of this tutorial will be GitHub pages.
After logging into Github.com, go to Account Settings -> SSH Keys and click “Add SSH Key” as shown…
Make sure you copy and paste the SSH public key (such as id_rsa.pub) and not the private key(id_rsa).
In the GitHub repository, click on SSH as shown below to obtain the “SSH clone url”
Open Git Bash terminal and navigate to working directory in which you want to pull down the files of the website. Type …
git clone git@github.com:username/username.github.io.git
The SSH URL will be different for you. But it will start with git@github.com: and ends with .git.
You now get a new folder with the source code of the site. Git downloaded that from the server to your local machine when you invoked the “git clone” command.
Now you can make changes to the source code on your local machine.
Commit to git local repository…
git add .
git commit -m “changes”
And push to server …
git remote -v
git push origin master
See previous tutorial on more info about these commands.
git remote -v
git push origin master
Changes have now been pushed to website.
When you run “git push” to connect to server, you may be prompted to enter your pass phrase. This was the pass phrase that you picked when you generated your ssh keys.