在实际项目中使用git推代码踩过的坑

Git使用中出现的状况:

BUG集锦:

  1. On branch dev nothing to commit, working tree clean

image-20200326231641747

说明在dev分支上,没有什么提交,很干净;

2.fatal:couldn't find remote ref devimage-20200326232442805

新建项目时,pull出现的报错信息,说明项目还有有文件,时空的直接进行推代码

3.git push -u origin devimage-20200326233752933

将代码推至dev分支上

4.现有的代码在dev分支上,将dev分支代码合并到master分支上

4.1 git branch 查看现有分支

4.2 git checkout master 切换到master分支上

4.3 git pull 拉去代码

4.4 git add . 提交代码信息

4.5 git commit -m "*****" 合并dev分支代码

4.6 git push. 推代码

image-20200326235311045

5.error:src ref spec master does not match any. Error:failed to push some refs to

常见原因:

5.1 本地git长裤目录下为空

5.2 本地仓库add后没有commit

5.3 git init错误

6. fatal:remote origin already exits

首先删除:git remote rm origin

再继续执行

7. Error:failed to push some refs to

​ 起初我们在远端创建仓库时,已经存在README文件和.gitignore文件,然后将本地关联远端,所以在本地推代码至远端,会报错failed,因为两端都有内容,却没有任何联系,所以在拉取或者推代码时,git总会让你先拉取后推代码,但是拉取却是失败的;

​ 方案:为了避免报错,我们在远端常见仓库时,最好是创建一个空的仓库,在github创建时会提示:

Skip this step if you're importing an existing repository(如果你想导入库,请跳过此步骤)

This will let you immediately clone the repository to your computer(允许你将库克隆到你的计算机上)

8. Error:pathspec 'master' did not match any file(s) known to git
9. fatal:refusing to merge unrelated histories

​ 因为远程仓库已经存在代码记录了,并且那部分代码没有和本地仓库进行关联,我们可以使用如下操作允许pull未关联的远程仓库旧代码;

​ 方案:git pull origin master --allow-unrelated-histories

10.please make sure you have the correct access rights and the repository exists

需要重新配置本地ssh密钥

猜你喜欢

转载自www.cnblogs.com/Zhao159461/p/12578829.html