0%

一些自己用git_github的整理

前提:搞定了git的用户配置、 与自己的github账户进行了ssh绑定链定、创建一个属于这个项目的仓库

超级常用的指令

git add . | 把此目录底下的所有文件加入提交缓存中
git clone | 将一个github上的仓库资源克隆到本地
git commit -m '' | 提交文件到指定的仓库中,在''中填上本次提交的信息


将本地项目文件推送(push)到github上的仓库的要打代码的流程

建立本地仓库与远程仓库链接:git remote add origin 项目链接
添加根目录上的所有文件到缓存区:git add .
提交文件到指定的仓库中,在’’中填上本次提交的信息:git commit -m ''
把远程仓库和本地仓库同步:git pull --rebase origin main
把仓库中的文件推送到github仓库:git push -u origin main
结束


一些遇到的错误情况

  1. git返回错误:error: src refspec main does not match any时,表示此时你所要提交文件到的分支(branch)不在,个人创建仓库(Repositories)的时候一般都是为master/main两种名字,如果你上面所输入的提交代码为git push -u origin main又出现开头所说的错误的话,此时只需要将github上你的仓库的分支(branch)修改名字为‘main’,输入代码git branch -m master main

    贴上github为什么要这么做的原因:
    GitHub is working on replacing the term “master” on its service with a neutral term like “main” to avoid any unnecessary references to slavery
    GitHub正在努力将其服务中的“master”一词替换为“main”等中性术语,以避免任何不必要的奴隶制提及(机翻)

  2. git返回错误:fatal: unable to access '仓库地址': Failed to connect to github.com port 443 after 21057 ms: Couldn't connect to server时,表示网络出现错误,可能是此时电脑开着网络代理工具
    输入git config --global --unset http.proxy
    git config --global --unset https.proxy
    用来取消git的网络代理使用