Skip to content

Instantly share code, notes, and snippets.

@piotrkundu
Created May 8, 2022 21:28
Show Gist options
  • Save piotrkundu/8e43a378a04278ea7cfb8dd10e711ae2 to your computer and use it in GitHub Desktop.
Save piotrkundu/8e43a378a04278ea7cfb8dd10e711ae2 to your computer and use it in GitHub Desktop.
  1. Create the key:
ssh-keygen -t ed25519 -C "example@example.com"
  1. Choose the default location by pressing enter: ~/.ssh/id_ed25519

  2. Copy the content of the key

cat ~/.ssh/id_ed25519.pub | clip
  1. Go to github.com and then Settings (top right arrow next to your profile avatar) and "SSH and GPG keys" left hand navigation and paste (yes, it's short and not I'm not using that key for anything):
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBQCKFBqfPt3WTChWiIUJxa3ZH/Vpeq35dliw1ex6wRm example@example.com

  1. Start the ssh-agent service on Windows. Start Windows Powershell with "Run As Administrator":
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent

image

NOTE: If you miss this step then you will get unable to start ssh-agent service, error :1058 error

  1. Now add the key to ssh-agent:
eval `ssh-agent -s`
ssh-add -K ~/.ssh/id_rsa
  1. Now make sure that ssh-agent is started everytime you start MSYS2 so that you don't have to provide your password(SSH key passphrase) everytime you use git, ssh or anythin using your ssh key.
nano .profile

and paste

env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
    (umask 077; ssh-agent >| "$env")
    . "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
    agent_start
    ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    ssh-add
fi
unset env

NOTE: The file is located in your Windows home folder: C:\Users\%username%\.profile - not in MSYS folder structure like everything else.


TROUBLESHOOTING

I "pinned" my MinGW64 application to the taskbar on Windows 11 and when I restarted it to check the ssh-agent is working it it's just stuck: wrong

And when I tried to close it I got this message: mintty

To fix it just use search and start from the Start Menu - do not pin to taskbar (which worked with Git Bash and Windows 10). This is how it should look like right and you provide the passphrase once and now you can use git.

Also I got this weird ^[[200~ pasted when I use Ctrl+V on EN language Windows 11 and that apparently called "bracketed paste mode". I just disabled it with one line in \msys64\etc\inputrc

set enable-bracketed-paste off

You can also do it for your user only by having your own .inputrc in your home folder:

touch ~/.inputrc
nano ~/.inputrc

And then paste:

set enable-bracketed-paste off

LINK: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/working-with-ssh-key-passphrases


Git config and aliases:

Type this in the MSYS prompt to change default editor to nano

git config --global core.editor "nano"
git config --global -e

And the paste this bunch of aliases. Anytime you forget what they do, just type git al and it will list all aliases. (That is one of the aliases below).

[init]
 defaultBranch = main

[core]
 editor = nano

[user]
 name = YOUR NAME
 email = example@example.com

[credential]
 modalPrompt = true

[alias]
  al = config --get-regexp alias 
  br = branch
  ci = commit
  cim = commit -m
  cia = commit --amend
  co = checkout
  cob = checkout -b
  cp = cherry-pick -x
  d = diff -w
  lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
  r = remote -v
  rh = reset --hard
  sm = submodule update --init --recursive
  s = status -sb
  st = status 
  t = tag -l
  unstage = reset HEAD
  uncommit = reset --soft HEAD^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment