Git.exe将不会执行.bashrc

时间:2018-09-24 18:18:43

标签: git ssh visual-studio-code git-for-windows

我刚刚下载了适用于Windows的Git(便携式2.19.0.windows.1),并尝试设置SSH密钥。我使用GitKraken,它已经帮助我生成了2个密钥。我根据the Github Help.bashrc中创建了.bash_profile(也尝试过%USERPROFILE%)来添加它们。如果先执行sh然后执行git pull,我可以拉。但是不能直接从Windows cmd git pull进行。它显示以下错误:

D:\Data\Blog (master -> origin)
λ git pull
git@gitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

我运行ssh -vT git@gitlab.com来发现我的ssh密钥未添加。似乎git.exe无法运行我的.bashrc,因此即使ssh-agent也无法启动。这导致我的VS Code无法使用git。

如何解决此问题,使其可以自动启动ssh-agent并添加SSH密钥?

我的.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 个答案:

没有答案