This is a tutorial of git for the beginners
更新教程 link
使用git GUI来对github库进行操作是最方便的, 教程链接.
如果想使用命令行(Bash)方式, 可参考以下教程:
- github账号和本地建立ssh连接(仅初次使用git需要)
ssh-keygen -t rsa -C "邮箱"
在资源管理器打开C盘>用户>.ssh,找到id_rsa.pub文件,记事本打开,复制到github主页->setting->ssh and GPG keys, 点击add keys
测试:输入ssh -T [email protected]
, 如果结果为successful,说明github账号已经和本地连接
-
克隆仓库到本地(仅需1次, 可以反复修改和同步)
git clone github上的仓库网址(.git结尾的)
仓库网址的获取: 打开项目->code,复制.git结尾的网址,注意不要用浏览器直接复制的网址
-
修改仓库后把本地进度同步到github, 步骤如下: 到本地的仓库文件夹下,右键打开git bash, 依次输入如下命令:
git init
git config --global user.name '你的github用户名'(也可以任意填写)
git config --global user.email '你的绑定邮箱'(也可以任意填写)
git checkout -b 要提交的branch名(不用加引号)
(输入 git branch
可查看当前branch, 提交前确认当前已经切换到你想上传文件的branch)
git add 上传的文件名(.则上传全部文件)
git commit -m '备注'
git remote add origin github上的仓库网址(.git结尾的)
(如果这个branch下有本地没有的文件,需要加下面这句:
git pull --rebase origin branch名
建议先把整个仓库clone下来,始终在本地修改,这样就不会有此问题)
其中rebase命令的含义: link
git push -u origin 要提交的branch名
这一步很容易报错(fail to access...), 解决方案见下文
最常发生的报错是push失败, 解决方法详见case 2
$ git pull --rebase origin main
fatal: unable to access 'https://github.com/user_name/xxxxx.git/': Failed to connect to github.com port 443 after 21067 ms: Timed out
解决方案:
git remote add origin 项目仓库网址(.git结尾的)
如果不奏效, 可能是代理的事, 可尝试该博客中提出的解决方案.
注意: github上传的单个文件不要超过25M
$ git push -u origin main
fatal: unable to access 'https://github.com/user_name/xxxxx.git/': OpenSSL SSL_read: Connection was reset, errno 10054
解决方案:
输入命令:
git config --global http.sslVerify "false"
git config --global http.sslBackend openssl
如果还不奏效, 则重新初始化:
git init
git config --global user.name '你的github用户名'(也可以任意填写)
git config --global user.email '你的绑定邮箱'(也可以任意填写)
fatal: protocol 'https' is not supported
解决方案详见: link