Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH option in gitconfig #397

Open
cgimenes opened this issue Aug 28, 2024 · 2 comments
Open

SSH option in gitconfig #397

cgimenes opened this issue Aug 28, 2024 · 2 comments

Comments

@cgimenes
Copy link

Github recommends to use SSH over HTTPS, and some people like me uses only SSH to clone repos.
So, it would be good to have a setting in the .gitconfig to avoid adding -p on all clone commands.

@DrumRobot
Copy link

By setting the pushInsteadOf option in git config, you can automatically redirect git push commands that target a specific URL to an alternative URL. This option is particularly useful when you want to convert HTTPS URLs to SSH URLs, allowing you to push through SSH instead of HTTPS.

For example, with the following configuration:

[url "ssh://git@github.com/"]
    pushInsteadOf = https://github.com/

Git will attempt to push to ssh://git@github.com/ whenever you push to a URL starting with https://github.com/. This means:

  • Even if you clone the repository using HTTPS, Git will push using SSH.
  • You can thus use SSH authentication for git push without manually adjusting the URL.

With this setup, you no longer need to use commands like ghq -p. The ghq -p option normally forces ghq to clone a repository with an ssh URL instead of https, but by configuring pushInsteadOf, you can clone with HTTPS and still push with SSH automatically.

@cgimenes
Copy link
Author

By setting the pushInsteadOf option in git config, you can automatically redirect git push commands that target a specific URL to an alternative URL. This option is particularly useful when you want to convert HTTPS URLs to SSH URLs, allowing you to push through SSH instead of HTTPS.

For example, with the following configuration:

[url "ssh://git@github.com/"]
    pushInsteadOf = https://github.com/

Git will attempt to push to ssh://git@github.com/ whenever you push to a URL starting with https://github.com/. This means:

  • Even if you clone the repository using HTTPS, Git will push using SSH.
  • You can thus use SSH authentication for git push without manually adjusting the URL.

With this setup, you no longer need to use commands like ghq -p. The ghq -p option normally forces ghq to clone a repository with an ssh URL instead of https, but by configuring pushInsteadOf, you can clone with HTTPS and still push with SSH automatically.

Thanks, but my main point is cloning through SSH; I don't want to authenticate using HTTPS. And, using your solution I would have to authenticate through both protocols while working on private repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants