note/tech/git 和github常用.md
2025-11-19 10:16:05 +08:00

27 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# git 和 github
## 密码访问 or SSH访问
github默认的配置是http访问但是建议使用ssh访问这样更加便捷
1. 在github中添加ssh密钥。settings --> SSH and GPG keys),NEW SSH KEY。key可以用自己电脑上的任何公私密钥也可以手动生成`ssh-keygen -t rsa -b 4096 -C "your_email@example.com"`;然后粘贴私钥到自己家目录~下的.ssh/目录下公钥贴到github中注意rsa_id 和 rsa_id.pub公司要都要贴到自己home目录的.ssh 文件夹中。
2. github创建仓库时默认是这个配置
```shell
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/yourname/xxx.git #这一步需要修改成git@github.com:yourname/xxx.git 意思是使用ssh来更新而不是https。因为github已经禁用https更新了。
git push -u origin main
```
这么创建以后,在仓库的.git/config里面设置的是https访问github。如果要用ssh访问则必须要把remote地址改一下
```shell
[remote "origin"]
url = git@github.com:yourname/xxx.git
```
然后就可以用git push -u origin main了。
## 设置代理
```
git config --global
```