Git

How Git SSH Works | Beginner Git Tutorial

The “SSH” protocol stands for “Secure Shell”, which is used for security purposes while connecting the remote and local repositories, such as encrypting data pushed from a local machine to a GitHub hosting server over the internet. More specifically, this protocol can be utilized to clone an entire remote repository content or a specific branch.

This guide will discuss the following methods:

So, let’s start!

How to Git SSH Works?

The user’s local machine can utilize the SSH agents to communicate with an SSH server instead of using the local machine as the SSH client.

How to Clone Git Remote Repository With SSH URL?

To clone the Git remote repository with the SSH URL, first, open up the GitHub hosting service, go to the desired remote repository and copy the SSH URL. Then, launch the Git terminal and move to the local repository. After that, run the “$ git clone” command with the SSH URL and clone it.

Now, implement the above-discussed instructions!

Step 1: Copy SSH URL
First, open up GitHub hosting service, go to the remote repository, hit the below-highlighted button, and copy the repository SSH URL:

Step 2: Move to Git Repository
Run the “cd” command and navigate to the existing Git local repository:

$ cd "C:\Users\nazma\Git\Test_4"

Step 3: Clone Repository With SSH URL
Now, clone the remote repository using the “git clone” command along with copied SSH URL:

$ git clone git@github.com:GitUser0422/Test_repo.git

It can be observed that the remote repository is cloned successfully:

Now, move ahead and learn how to clone specific branches with SSH URL.

How to Clone Git Remote Branch With SSH URL?

Like the whole repository, Git users can clone the specific remote branch with the SSH URL. To do so, follow the below steps.

Step 1: Clone Specific Branch
Execute the below-provided command with the “–branch” option to clone the specific branch:

$ git clone --branch master git@github.com:GitUser0422/Test_repo.git

Step 2: List Remote URLs
Check the list of remote URLs through the “git remote” command with the “-v” option:

$ git remote -v

According to the below output, the remote URL list is empty:

Step 3: Add Remote URL
Now, execute the “git remote add dev” command with SSH URL:

$ git remote add dev git@github.com:GitUser0422/Test_repo.git

Step 4: Verify Remote URL
Run the “git remote” command with the “-v” option to verify if the remote URL has been added:

$ git remote -v

It can be observed that we have successfully cloned the remote branch:

We have provided the easiest method to clone the Git remote repository and specific remote branch with the SSH URL.

Conclusion

To clone the Git remote repository with the SSH URL, first, open up the GitHub hosting service, go to the desired remote repository and copy the SSH URL. Then, launch the Git terminal and move to the local repository. After that, clone the remote repository with SSH URL using the “$ git clone” command. However, to clone a specific remote branch, execute the “$ git clone –branch <ssh-url>” command. This guide illustrated the procedure to clone the Git remote repository and specific remote branch with the SSH URL.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.