By default, most remote git repositories support pushing to HTTPS URLs. But sometimes you may need to use SSH instead of using HTTPS. In this article, we will learn how to use SSH instead of HTTPS in git. You can use these steps with your remote git repository hosted on GitHub or BitBucket.
How to Use SSH Instead of HTTPS in Git
Here are several ways to use SSH instead of HTTPS in git.
1. Setup Repository’s Origin Branch to use SSH
If you want to use SSH protocol instead of HTTPS, just add a remote branch to use SSH, as shown below. Replace username and repo name with the names of your user and repository respectively.
$ git remote add origin git@github.com:<username>/<repo name>.git
2. Modify Existing Repository
You can always modify pre-existing repository by modifying its .git/config file. Add the following lines to it.
[remote "origin"] fetch = +refs/heads/*:refs/remotes/origin/* -url = https://github.com/<username>/<repo name>.git +url = git@github.com:<username>/<repo name>.git
You can also use a shortcut command given below to do the same thing.
$ git remote set-url origin git@github.com:<username>/<repo name>.git
In this short article, we have learnt how to use SSH for your Git repository, instead of using HTTPS URL to push commits.
Also Read:
How to Encrypt File in Linux
How to Repair Ubuntu 18.04 using USB
How to Monitor Disk IO Performance in Linux
How to Monitor Outgoing HTTP Requests in Linux
How to Pair Airpods Pro with Ubuntu
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.