Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Git Change Remote URL to SSH (from HTTPS)

    Git Change Remote URL to SSH (from HTTPS)

    By RahulJanuary 5, 20233 Mins Read

    Git is a distributed version control system that is widely used for tracking changes in source code during software development. It allows developers to collaborate on projects and keep track of their changes without the need for a central repository.

    Advertisement

    One way to access a Git repository is via SSH (Secure Shell). SSH is a network protocol that provides a secure way to communicate with a remote computer over an unsecured network. Using SSH can be more secure and efficient than other methods, such as HTTP or HTTPS, for accessing Git repositories.

    If you want to change the URL of a remote repository in your local Git repository to use SSH, here are the steps to follow:

    Prerequisites

    Before you can change the remote URL to use SSH, you will need to do the following:

    1. Generate an SSH key pair. This consists of a private key and a public key. The private key is kept on your local machine, and the public key is uploaded to the remote repository.
    2. Add your public key to the remote repository. This allows your local machine to securely connect to the remote repository using the private key.

    If you are not familiar with generating SSH keys or adding a public key to a remote repository, you can find more information and instructions in the Git documentation or online tutorials.

    Changing the Remote URL

    Once you have generated an SSH key pair and added your public key to the remote repository, you can change the remote URL in your local Git repository as follows:

    1. Open a terminal window (Git Bash on Windows, or any terminal emulator on macOS or Linux).
    2. Change to the directory that contains the local Git repository.
    3. Run the following command to view the current remote repository URL:
      git remote -v 
      

      This will display a list of all the remote repositories that are linked to your local repository, along with their URL.

    4. To change the URL of a specific remote repository to use SSH, use the following command:

      1
      2
      # Syntax
      git remote set-url <remote> <user>@<host>:<path>

      Replace <remote> with the name of the remote repository (usually origin), <user> with your username on the remote host, <host> with the hostname or IP address of the remote host, and <path> with the path to the Git repository on the remote host.

      For example, to change the URL of the origin repository to “[email protected]:username/repo.git”, you would run the following command:

      git remote set-url origin [email protected]:username/repo.git 
      
    5. Verify that the URL has been changed by running the `git remote -v` command again. You should see the new SSH URL listed for the specified remote repository.

    That’s it! The remote URL for your local Git repository should now be changed to use SSH. You should now be able to push and pull changes to and from the remote repository using the git push and git pull commands as usual.

    I hope this helps! Let me know if you have any questions or need further clarification on any of the steps.

    git
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    How to Install MySQL 8.0 on RHEL & CentOS Stream 9

    How to Split Large Archives in Linux using the Command Line

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • What is the /etc/mtab File in Linux
    • The “Hello World” Challenge: Printing in 20 Different Programming Languages
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.