Linux环境上传文件到Github步骤及错误分析
Git上传文件(夹)步骤
-
在github网站上新建仓库(确保万无一失把
~/.ssh/id_rsa.pub
文件的公开**添加到github上) -
git init
//关联git上新建的仓库前,需要在linux中上传文件路径下,新建git仓库,在文件夹下有.git文件; -
git clone xxxxxx
//这里的应该是仓库的网址。作用:
拷贝一个 Git 仓库到本地,让自己能够查看该项目,或者进行修改; -
git add xxxx
//添加的文件名;或者
git add .
//上传当前路径中的所有文件和文件夹; -
git commit -m "xxxx"
//引号中为备注信息作用:
提交暂存区中; -
git push -u origin master
//把本地仓库传到github上面(以后可以省略-u
)
git上传文件错误分析
-
出现错误:
fatal:refusing to merge unrelated histories
解决:出现这个问题的最主要原因还是在于本地仓库和远程仓库实际上是独立的两个仓库。假如我之前是直接clone的方式在本地建立起远程github仓库的克隆本地仓库就不会有这问题了。$git pull origin master --allow-unrelated-histories
//远程仓库文件拉去到本地仓库$git push origin master:master
//将本地仓库的提交推送到远程github仓库上 -
连接Github时出现:
Failed to connect to github.com port 443: Connection refused
解决:一直访问不到端口,后来按照错误搜索也没有解决办法,后面找到一个也是因为端口访问错误的问题,就尝试了这种该法,终于成功了。 -
由于在解决第二个问题时,查询到一个解决方式,引发的另外一个错误:
Failed to connect to 127.0.0.1 port 1080: Connection refused
错误原因,由于命令行输入git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
解决:
查询是否使用代理:git config --global http.proxy
当然我肯定是有这个代理的,不然也不会出错。
取消代理:git config --global --unset http.proxy
问题即可解决
-
Gihub如何删除文件夹/修改文件夹名字 ?
解决:删除文件夹:git rm -f --cached filename
//–cached只删除缓冲区的filename文件git commit -m "备注信息"
git push -u origin master
修改文件夹名字:git mv -f oldfolder newfolder
git add -u newfolder
// (-u选项会更新已经追踪的文件和文件夹)git commit -m "changed the foldername whaddup"
git push -u origin master