Git SSH vs HTTPS: Which Should You Use?
A Git remote can use either an SSH or HTTPS URL to connect to GitHub and other hosting services. Both let you fetch and push code; the difference is how your computer authenticates. This guide compares the setup, tradeoffs, and common workflows so you can choose confidently or switch a repository from one protocol to the other.
Practice Git workflows →The quick answer
Choose SSH if you regularly work with repositories from a trusted computer and are comfortable setting up a key pair. Choose HTTPS if you prefer to authenticate through a credential manager, use a managed or temporary environment, or work on a network that blocks SSH. Neither option is universally more secure: keep private SSH keys and access tokens protected, and follow your organization's authentication policy.
| Topic | SSH | HTTPS |
|---|---|---|
| Authentication | SSH key pair | Credential manager or access token |
| Initial setup | Create and register a public key | Usually clone first, then authenticate |
| Network fit | May be blocked on port 22 | Often works wherever HTTPS is allowed |
| Best fit | Frequent development on a trusted device | Flexible or managed environments |
How Git SSH authentication works
SSH uses a key pair. You keep the private key on your computer and add the public key to your Git hosting account. When you connect, the server checks that your key is authorized without sending your private key to the server. An SSH agent can keep an unlocked key available for your session; a passphrase helps protect the key if its file is copied.
If you do not already have a suitable key, create one with a descriptive email comment:
ssh-keygen -t ed25519 -C "your_email@example.com"Follow the prompts, add the public key file (often ~/.ssh/id_ed25519.pub) to your account's SSH key settings, and keep ~/.ssh/id_ed25519private. Never upload or share the private key. See your host's current setup instructions for platform-specific agent and keychain steps. For GitHub, you can test the connection with ssh -T git@github.com; a successful authentication message does not provide an interactive shell.
How Git HTTPS authentication works
HTTPS connects to the repository over a web URL. When you push or access a private repository, the host asks Git to authenticate. Most providers support a credential manager or browser-based sign-in; if a token is required, create it through the provider and give it only the necessary permissions. Git hosting services generally do not accept your account password for Git operations over HTTPS.
Use a credential manager rather than putting a token directly in a remote URL, command, or script. URLs and shell history can be recorded or shared accidentally. Revoke a token that may have been exposed, then create a replacement. For organization-managed repositories, follow the provider's sign-in and single sign-on instructions.
Check or change your repository's remote
See which protocol the current repository uses by listing its remotes:
git remote -vAn HTTPS URL starts with https://. An SSH URL looks like git@github.com:OWNER/REPOSITORY.git. To change the existing origin remote, copy the exact URL from your hosting service and set it with:
git remote set-url origin git@github.com:OWNER/REPOSITORY.git
git remote -vReplace the example with your repository's actual URL. Changing the remote changes where future fetches and pushes connect; it does not alter your local commits or working files. You can switch back by setting origin to the HTTPS URL instead.
Troubleshooting SSH and HTTPS remotes
- If SSH says permission is denied, check that the correct public key is registered, the SSH agent has the matching private key, and the account has repository access.
- If SSH connections time out, your network may block the default SSH port. Ask your administrator about an approved SSH-over-HTTPS endpoint or use HTTPS if policy permits.
- If HTTPS repeatedly asks for credentials, check your credential manager and confirm that the token or browser authorization has access to the repository.
- If push is denied with either protocol, verify your repository permissions and branch protection rules; changing the URL does not grant additional access.
Git SSH vs HTTPS FAQ
Is SSH more secure than HTTPS for Git?
Both use encrypted connections and can be configured securely. SSH relies on protecting a private key; HTTPS relies on protecting a credential or token. Keep either credential out of source code and grant it only appropriate access.
Can I use SSH for one repository and HTTPS for another?
Yes. The protocol is configured per remote URL, so repositories on the same computer can use different protocols.
Does changing the remote URL affect my commits?
No. It changes the destination used for remote operations. Your branches, commits, and working tree stay as they are.