git推送文件到gitee
设置字体
注册gitee账号
-
设置姓名、个人空间地址
-
点击头像旁边的加号,新建仓库
安装git
-
windows风格命令,Git CMD
-
linux风格命令,Git Bash
# 设置姓名和邮箱,姓名是注册gitee时设置的姓名,邮箱是注册gitee的邮箱
git config --global user.name "chny"
git config --global user.email "xxxxx@163.com"
# 查看
git config user.name
git config user.email
# 查看.gitconfig,验证是否配置成功
添加SSH公钥
- 打开git bash,输入:ssh-keygen -t rsa -C "xxxxx@163.com"
- 一路enter后,生成SSH key,打开C:/User/用户/.ssh,id_rsa为私钥,id_rsa.pub为公钥
- 打开id_rsa.pub文件,复制key,添加到gitee的SSH公钥
- 验证是否添加成功,git bash输入:ssh -T git@gitee.com
推送文件到远程仓库
# 新建一个文件夹作为本地仓库,右键git bash打开,初始化为本地仓库
git init
# 将要推送的文件复制到该文件夹,将文件提交到暂存区
git add 文件名
# 将暂存区的文件提交到本地分支master,并添加备注
git commit -m "备注"
# 关联远程仓库
git remote add origin https://gitee.com/个人空间地址/路径名.git
# 将本地master分支的文件推送到远程master分支,第一次推送时需加 -u
git push -u origin master
-
路径为创建仓库时设置的路径
-
也可以在这里查看路径
-
将远程仓库同步到本地
git pull --rebase 关联远程仓库时设置的名称 远程分支名
- 第一次推送时会弹出一个弹框,需要输入用户名和密码,是gitee登录时的用户名和密码
- 第一次推送成功后会生成凭据,建议不要修改或删除,否则会报错:incorrect username or password ( access token )
添加或修改仓库
- 当本地仓库添加新文件或有修改时,只需将修改后的文件夹同步到远程仓库即可
git add 修改后的文件
git commit -m "备注"
git push origin master
- 拉取仓库时报错
# 拉取仓库
git pull --rebase origin master
# 报错如下
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.
# 解决方案
git add .
git commit -m "test"
# 本仓库暂存提交后即可重新拉取
- error1
# 报错:Failed to connect to github.com port 443: Timed out
# 解决方案:
git config --global --unset http.proxy
git config --global https.proxy
git config --global --unset https.proxy
- error2
# 报错如下:
$ git clone https://github.com/chniny/back_repo.git
Cloning into 'back_repo'...
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/chniny/back_repo.git/'
# 解决方案参考:https://blog.csdn.net/yjw123456/article/details/119696726
# gitlab生成token:https://blog.csdn.net/StefanTimber/article/details/103928742
- error3
# 错误还原:验证公钥是否添加成功时报错,ssh -T git@github.com
connect to host github.com port 22: Connection timed out
# 解决方案:进入公钥所在路径,创建配置文件如下
vi config
# 配置文件内容如下
Host github.com
User 注册github的邮箱
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443
# 参考:https://blog.csdn.net/nightwishh/article/details/99647545
- error4
# 报错: fatal: Not a git repository (or any of the parent directories): .git
# 解决方案
git init
- error5
# 报错:OpenSSL SSL_read: Connection was reset, errno 10054
git config --global http.sslVerify "false"
# 参考:https://www.cnblogs.com/fairylyl/p/15059437.html
- error6
# 报错:The following untracked working tree files would be overwritten by merge:
# 参考:https://www.cnblogs.com/objectZhu/p/13205803.html
git fetch origin
$ git clean -f
$ git reset --hard origin/main
以项目根目录作为仓库根路径,推送到github
# 进入项目根路径
git init
git remote add origin https://github.com/用户名/仓库名.git
git remote -v
git checkout -b main
git pull origin main
git add .
git commit -m "1"
git push -u origin main