Git

git常见命令使用方法

Linux使用Git

$ sudo apt install git   # 安装git
$ git config --global user.name "user name"
$ git config --global user.email "user email"
$ sudo apt install ssh   # 安装ssh
$ ssh-keygen -t rsa -b 4096 -C "your_id@xx.com" # 按三次enter生成ssh,your_github_id是你的github账户邮箱,如果设置过密钥,此处需要输入yes覆盖之前的密钥
$ cat ~/.ssh/id_rsa.pub  # 将id_rsa.pub文件的内容添加到github
$ ssh -T git@github.com  # 测试ssh有没有正常工作,如果是第一次使用ssh需要输入yes
$ git clone your_project # 此处需要使用ssh克隆代码,例如:git clone git@github.com:xxx.git

github常见问题

1.如果github已经添加了ssh,git操作还是需要输入username以及password

$vim .git/config  # 查看url是不是ssh方式,如果不是可以将本地的仓库删除,重新以ssh方式拉取代码
$git remote -v    # 查看url是不是ssh方式

2.如果已经使用http克隆了代码,可以使用以下方式修改为ssh

git remote set-url origin git@github.com:xxx.git将url设置为ssh方式

也可以修改.git/config文件来修改url方式

3.如果修改了url方式之后git pull、git push等报以下错误:

git@github.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并更新github中的ssh来解决

4.如果git clone\push\pull等连接服务器时报错

kex_exchange_identification: Connection closed by remote host
Connection closed by 20.205.243.166 port 22

一般都是网络原因导致

5.如果提示输入密码

可以执行以下操作

$ vim ~/.ssh/config
# config文档添加以下内容
Host github.com
identityFile ~/.ssh/id_rsa # 这里是ssh生成的私钥文件名
Host github.com
Hostname ssh.github.com
Port 443
User git
posted @ 2022-05-11 16:07  滴哒哒哒  阅读(26)  评论(0编辑  收藏  举报