Git Remote HTTPS to SSH (GRHS)

Switching the remote Git URL from HTTPS to SSH is a beneficial step for developers looking to enhance security and simplify authentication when accessing repositories. With HTTPS, users typically have to enter their credentials (username and password) each time they interact with a protected Git repository. This approach can feel cumbersome, especially for users who frequently pull or push to a repository, as it requires repeated authentication. On the other hand, using SSH allows for automatic authentication without manual credential entry every time, as long as the SSH key is set up on the local machine and synced with the Git service provider account (such as GitHub or GitLab).

Switching from HTTPS to SSH also adds an extra layer of security. With SSH, communication between the local machine and the Git server is encrypted using a private and public key, so credentials are not exposed with each connection. To switch from HTTPS to SSH, the main steps involve checking the current remote URL with the command git remote -v and then changing it with git remote set-url origin [SSH URL], where the SSH URL can be found in the repository settings. This makes working with Git more secure and convenient, especially for long-term projects.

1. Open Git Bash.

2. Change the current working directory to your local project.

3. List existing remotes to get the name of the remote you want to change.

git remote -vorigin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

4. Change your remote URL from HTTPS to SSH with the git remote set-url command

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git

5. Verify that the remote URL has changed.

git remote -v
# Verify new remote URL
origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
origin  git@github.com:USERNAME/REPOSITORY.git (push)
The next time you use git fetch, git pull, or git push to a remote repository, you will be prompted for your GitHub username and password.

  • If you have two-factor authentication enabled, you will need to create a personal access token to use in place of your GitHub password.
  • You can use the credential helper so that Git will remember your GitHub username and password every time you interact with GitHub.


Post a Comment

Previous Next

نموذج الاتصال