Git pull HTTPS, push SSH

Public Git repos, GitHub Gists, and GitLab Snippets can use HTTPS for “git fetch”, “git pull”, and other Git download operations. Using HTTPS to download and verifying the author PGP signed Git commits can help assert that the content is from the intended authors. Git download operations over HTTPS are perhaps twice as fast as Git over SSH and use less CPU. By default, Git verifies SSL certs.

Typical Git hosting providers such as GitHub require SSH for enhanced security. Since “git push” operations typically take longer than “git pull”, particularly where pre-commit hooks and PGP commit signing are used, SSH speed penalty on “git push” is often acceptable.

For developers there are speed benefits from a hybrid Git configuration where Git downloads use HTTPS and Git uploads use SSH. Git has intrinsic functionality for this setup in a global configuration. The one-time setup below uses “https://” for the remote repo URL instead of “ssh://”. Replace “your_username” with your GitHub username for SSH GitHub Gists Git push.

git config --global url."ssh://".pushInsteadOf

git config --global url."ssh://".pushInsteadOf

git config --global url."ssh://".pushInsteadOf

Note that GitLab Snippets doesn’t require an extra configuration setting like GitHub Gists does.

The file ~/.ssh/config is typically set for Git SSH keys.

This makes all GitHub and GitLab public repos push over SSH, unless overridden in a repo’s own Git config. Confirm by git remote -v in a repo.

If experiencing problems on “git push”, check this matches the desired Git repo:

git config --get remote.origin.url

In particular, it must NOT have a trailing slash like repo/