解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes.


 1.
在使用git 对源代码进行pushgitHub时可能会出错,信息如下:

 

解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第1张图片

2.此时很多人会尝试下面的命令把当前分支代码上传到master分支上。

$ git push -u origin master

但依然没能解决问题


解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第2张图片
 

 

 

 

3.出现错误的主要原因是github中的README.md文件不在本地代码目录中


解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第3张图片
 

 

4.可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

 


解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第4张图片
 
5、此时又出现了另外一个问题:cannot pull with you have unstaged changes

这说明“有修改过的文件,但是没有放到暂存区”,因此使用
git stash

 

然后再git pull --rebase (每次push之前最好这样做一次)就可以正常提交了。
 
解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第5张图片
 

 

6.执行上面代码后可以看到本地代码库中多了README.md文件

 


解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第6张图片
 

 

7.此时再执行语句 git push -u origin master即可完成代码上传到github

 


解决failed to push some refs to git和Git Cannot rebase: You have unstaged changes._第7张图片
 

你可能感兴趣的:(git)