Git 常用命令及坑记录

Last updated on 9 months ago

配置用户名及邮箱

git config可以配置git的参数,可以使用git config --list查看已经配置的git参数。

其中有三个级别的保存位置,--system--global--local,分别

  • 表示所有用户(本系统)
  • 当前用户(全局)
  • 本地配置(当前目录)

默认使用--local

1
2
git config --global user.name "houshuai" 
git config --global user.email "houshuai@bjgoodwill.com"

获取远程仓库

1
git clone git@git.com

生成SSH秘钥

1
ssh-keygen -t rsa -C "hou3125378@live.com"

常见问题

没有生成SSHkey或者找不到对应的 SSHkey

1
2
3
4
Permission denied(publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access right
and the repository exists

解决:

  1. 生成SSHKey

    1
    ssh-keygen -t rsa -C "XXX@qq.com"
  2. debug

    1
    ssh -v git@github.com
  3. agent

    1
    ssh-agent -s
  4. 将对应的SSHKey

    1
    ssh-add ~/.ssh/id_rsa

​ 到这里如果遇到这个问题

Could not open a connection to your authentication agent

  1. 啥意思我也不知道

    1
    eval `ssh-agent -s`
  2. 重新指向

    1
    ssh-add ~/.ssh/id_rsa

​ 自己遇到这个问题不是没生成sshkey,而是多个sshkey 没有对应好

​ 参考地址:Git报错解决:git@gitee.com: Permission denied (publickey). - 尚码园 (shangmayuan.com)


Git 常用命令及坑记录
http://example.com/2021/11/19/Git_Cmd/
Author
Harris
Posted on
November 19, 2021
Licensed under