1、新建一个GitHub项目
2、下载并使用Git进行上传项目
下载Git工具
下载地址:https://git-scm.cn/downloads/win
我这里选择了一个项目进行克隆到我自己的GitHub上,下载并解压项目。
在项目内处打开Git bash
:
配置Git
配置Git邮箱
git config --global user.name "[github用户名]"
git config --global user.email "[github邮箱]"
配置ssh密钥
在Git Bash中执行如下命令
ssh-keygen -t ed25519 -C "[github邮箱]"
执行命令会上你设置公私密钥保存位置和设置密码,完成后会生成对应ssh公钥还有私钥。
找到生成的公钥,然后复制到GitHub中。
登录 GitHub → Settings → SSH keys → New SSH key → 粘贴公钥
上传完公钥可以进行测试连接:
ssh -T [email protected]
上传项目
git init #执行初始化
git add . # 添加所有文件
git commit -m "Initial commit" # 提交到本地仓库
git remote add origin [email protected]:[github用户名]/[项目名称].git #关联远程仓库
git push -u origin main # 首次推送需关联上游分支
如果ssh连接项目传不上去可以进行设置代理
,如果设置代理还能进行上传项目,则更换HTTPS
进行上传项目。
设置代理
git config --global http.proxy http://proxy.example.com:8080
git config --global https.proxy http://proxy.example.com:8080
设置完代理继续执行git push -u origin main
更换HTTPS
git remote set-url origin https://github.com/your-username/repo.git
git push -u origin main # 使用 HTTPS 推送
使用HTTPS会让你进行git和Github用户认证,正常登录认证即可。