使用Git遇到的问题及解决方案(初级)

第一次使用Git进行代码提交,遇到一些问题,于此记录并分享之

准备工作

首先做了一个练习项目,在本地项目目录进行了初始化命令:

git init

在github网站新建了一个repository,勾选了Initialize this repository with a README,cloneSSH格式的仓库地址,现在开始提交:

git add -A
git commit -m "提交备注信息"//可选
git remote add git@github.com:account/repository

错误及解决方案

提示出错信息:
fatal: remote origin already exists.
解决方案:

git remote rm origin
git remote add git@github.com:account/repository

这个错误应该不会再出现了。
然后提交的时候,又出现错误:
fatal: Could not read from remote repository.Please make sure you have the correct access rights.and the repository exists.
出现这个问题是因为,没有在github账号添加SSH key
解决方案: 这个错误可以用命令行处理掉,如下:

ssh-agent
ssh-add ~/.ssh/id_key

但简洁的方法是使用GitGui的show SSH Key工具,如图所示:
GitGui的show SSH Key工具
然后将生成的SSH Key复制,打开Github网站,在setting选项页中点击SSH and GPG keys链接,
SSH and GPG keys
点击右上角的New SSH Key按钮,将之前复制的SSH Key粘贴上去,title随便起个名字。
于此,这个错误已经解决了。
又出现新的错误:
failed to push some refs to ‘[email protected]:account/repository
原因在于github上创建仓库,建立README.md,导致该文件不在本地代码中,可以通过以下方式解决:

git pull --rebase origin master
//把远程服务器github上面的文件拉下来
//再次执行git push origin master即可完成代码上传
git push origin master

终于,项目上传到Git仓库中了。
(待续)

猜你喜欢

转载自blog.csdn.net/ccaoee/article/details/52190623