Header image for the post titled Git: setting up on Windows

My go-to notes for whenever I have to re-setup git and github on Windows.

  • Get git and Cygwin (GNU tools for windows) for ssh-keygen and ssh-agent. Alternatively you can get MINGW64 terminal/environment that includes both git and the required tools.
  • To get connected to github, create a keypair:
ssh-keygen -t ed25519 -f id_rsa -C "your_email@example.com"
  • The private key need to be placed in ~/.ssh, and named “id_rsa” for git to find it. Add the private key to github through their interface.
  • Add the following code in ~/.bashrc to start ssh-agent on terminal open.
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