-
-
Save mortenege/42b12a82f7d79877171af84c7d0a0714 to your computer and use it in GitHub Desktop.
1. This assumes an SSH keypair exists, usually in ~/.ssh (windows C:\Users\<username>\.ssh) | |
2. This assumes a git repository exists, otherwise create one as usual `git init` | |
3. Create a Repository on GitHub | |
4. Add SSH key to GitHub | |
5. Add the remote origin from gthub | |
``` | |
git remote add origin [email protected]:<username>/<repo>.git | |
``` | |
use `git remote -v` to verify | |
6. Edit your SSH config-file `~/.ssh/config` (windows `C:\Users\<username>\.ssh\config`) and add a Host | |
``` | |
Host github | |
HostName github.com | |
User git | |
IdentityFile "path/to/ssh/private-key" | |
IdentitiesOnly yes | |
``` | |
7. Edit the git projects config-file `.git\config` and add in [core] | |
``` | |
sshCommand = "ssh -F <path/to/ssh/config/file>" | |
``` | |
8. Use git push like usual | |
``` | |
git push origin master | |
``` |
This is very helpful! I found it also works with just one line in .git/config: sshCommand = "ssh -i ~/.ssh/github_key" Which does not require editing two files.
Thanks!
Shorter and works well, thank you!
This was helpful, thank you both! I'll add that the ssh command can also be set via the GIT_SSH_COMMAND
environment variable if editing the config is inconvenient.
Ill just add that for some reason this did't work and trying git push origin main
(my branch is called main, not master) I was getting [email protected]: Permission denied (publickey)'.
. However putting only the following in the ~/.ssh.config file:
Host github.com
IdentityFile "path/to/ssh/private-key"
did work. So someone may want to try that if they are having the same issue as me. Maybe someone smart may immediately identify why the original .ssh/config was not working for me.
This is very helpful!
I found it also works with just one line in .git/config: sshCommand = "ssh -i ~/.ssh/github_key"
Which does not require editing two files.
Thanks!