Git.exe won't execute .bashrc

193 Views Asked by At

I have just downloaded Git for Windows (portable 2.19.0.windows.1) and try to set up SSH keys. I use GitKraken and it already helped me generate 2 keys. I create .bashrc (also tried .bash_profile) in my %USERPROFILE% according to the Github Help to add them. I can pull if I execute sh and then git pull. But can't if git pull directly from Windows cmd. It shows the following error:

D:\Data\Blog (master -> origin)
λ git pull
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I run ssh -vT [email protected] to find out my ssh keys aren't added. Seems that git.exe won't run my .bashrc so even ssh-agent doesn't start. This causes my VS Code can't use git.

How to fix this so it can automatically start ssh-agent and add SSH keys?

My .bashrc:

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

# Shinoka part
add_my_ssh () {
    ssh-add /C/Users/shinoka/AppData/Roaming/.gitkraken/profiles/d6e5a8ca26e14325a4275fc33b17e16f/ssh/gitkraken_Shinoka-Yoga_github_rsa >| /dev/null
    ssh-add /C/Users/shinoka/AppData/Roaming/.gitkraken/profiles/d6e5a8ca26e14325a4275fc33b17e16f/ssh/gitkraken_Shinoka-Yoga_gitlab_rsa >| /dev/null
}
# end Shinoka part

# 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
    add_my_ssh
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
    add_my_ssh
fi

unset env
0

There are 0 best solutions below