git使用

设置代理

参考Git设置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//设置全局代理
//http
git config --global https.proxy http://127.0.0.1:1080
//https
git config --global https.proxy https://127.0.0.1:1080
//使用socks5代理的 例如ss,ssr 1080是windows下ss的默认代理端口,mac下不同,或者有自定义的,根据自己的改
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

//只对github.com使用代理,其他仓库不走代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
//取消github代理
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

//取消全局代理
git config --global --unset http.proxy
git config --global --unset https.proxy

Github上传项目

首先New repository

填写项目信息创建仓库

上传项目的命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#第一次上传
echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:h0pe-ay//*****..git
git push -u origin main

#后面几次上传
git remote add origin git@github.com:h0pe-ay/*****.git
#git branch -M main
git branch -f main HEAD
git push -u origin main

更新项目

1
2
3
4
5
git add *
git commit -m ""
git branch -f main HEAD
git push -u origin main
git push origin master -f

生成ssh key

1
2
#生成ssh key
ssh-keygen -t rsa -C "youremail@example.com

在C盘->用户名->.ssh文件夹下有个id_rsa.pub文件复制到github设置中SSH and GPG keys->New SSH key

push超时

参考文章git报错ssh: connect to host github.com port 22: Connection timed out

  • C盘->用户名->.ssh文件夹下创建config文件添加如下信息
1
2
3
4
5
6
Host github.com
User YourEmail
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

git使用
https://h0pe-ay.github.io/git使用/
作者
hope
发布于
2023年6月27日
许可协议