Switching the remote Git URL from SSH to HTTPS can be useful in certain scenarios, especially when SSH connections face issues or when working in environments that restrict the use of SSH protocols. HTTPS is often easier to use in stricter networks because it operates over port 443, which is commonly allowed by standard firewalls, whereas SSH uses port 22, which may sometimes be restricted. With HTTPS, users authenticate using a username and password or a personal access token, making it a more flexible choice for users who don’t have or prefer not to use SSH keys.
Although HTTPS requires repeated authentication, this can be managed with Git’s credential helper, which allows users to temporarily store their credentials in memory or secure storage for a specified time, reducing the need to re-enter the username and password for every Git operation. To switch from SSH to HTTPS, the main steps involve checking the current remote URL with git remote -v and then changing it using git remote set-url origin [HTTPS URL], where the HTTPS URL can be found in the repository settings on platforms like GitHub or GitLab.
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 -v
origin git@github.com:USERNAME/REPOSITORY.git (fetch)
origin git@github.com:USERNAME/REPOSITORY.git (push)
4. Change your remote URL from SSH to HTTPS with the git remote set-url command
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
5. Verify that the remote URL has changed.
git remote -v
# Verify new remote URL
origin https://github.com/USERNAME/REPOSITORY.git (fetch)
origin https://github.com/USERNAME/REPOSITORY.git (push)
- 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.