- Create the key:
ssh-keygen -t ed25519 -C "[email protected]"
-
Choose the default location by pressing enter:
~/.ssh/id_ed25519
-
Copy the content of the key
cat ~/.ssh/id_ed25519.pub | clip
- 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 [email protected]
- 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
NOTE: If you miss this step then you will get unable to start ssh-agent service, error :1058
error
- Now add the key to ssh-agent:
eval `ssh-agent -s`
ssh-add -K ~/.ssh/id_rsa
- 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.
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:
And when I tried to close it I got this message:
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
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
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 = [email protected]
[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^