software development GIT

Git 1:1 - https vs ssh. And what it means between origin and local

16-Feb-2025 - Muthomi Kathurima

 

When learning git, one of the first things to learn is origin vs local.

Origin

This is the remote repository of a project. it can be hosted in Github, Bitbucket, Gitlab or any other hosting platform for code. Origin specifically refers to the default branch in this remote repository

Local

This refers to the repository you have in your computer. Its a representation of the project files present in your local laptop

You can be able to pull or push code to one of the remote repositories through 2 methods that are popular and used, HTTPS or SSH. This protocols are in all major service providers for hosting repositories. HTTPs refers to Hypertext Transfer Protocol Secure while SSH refers to Secure Shell.

One of the issues with HTTPS protocol is that it requires username and password every time its being used. one of the ways to spot it is to check the url in .git/config under [remote "origin"].

if the url starts with git@ its a ssh configuration else if it starts with https:// its a HTTPS config.

[remote "origin"]
    url=git@github.com:<usr>/<repo>.git
[remote "origin"]
    url=https://github.com/<usr>/<repo>.git

To eliminate the need to use https, you can switch to ssh by modifying the origin url value to git@. With ssh, all you need to do is, generate an rsa ssh key and configure your profile with the ssh key. this will ensure you never have to use username and password, which exposes also your code to more risk.

This piece assumes you know the basics of git. I will be sharing more on git if this article gathers traction or interest.