Git Error: failed to push some refs to Updates were rejected because the remote contains work tha

1、运行git push -u origin master 时报错如下:
! [rejected] master -> master (fetch first)
error: failed to push some refs to ‘[email protected]:******/configserver.git’
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.
hint: See the ‘Note about fast-forwards’ in ‘git push --help’ for details.
Git Error: failed to push some refs to Updates were rejected because the remote contains work tha_第1张图片
修改方案:
先 运行git pull --rebase origin master,【注:pull=fetch+merge]
将远程仓库代码拉到本地合并后;
再运行git push -u origin master即可完成代码上传到github
Git Error: failed to push some refs to Updates were rejected because the remote contains work tha_第2张图片
2、将本地仓库上传到远程仓库步骤
1)git init #创建本地仓库
2)git add . #添加所有文件
git add somefile #添加某一个文件
3)git commit -m ‘第一次提交’ #将文件添加到仓库
4)git remote add origin [email protected]*****/configserver.git #连接仓库
5)git push origin master #将本地代码提交到远程仓库
如果报上面的错误的话,先执行git pull --rebase origin master
再执行 git push origin master
其他:git status #查看状态

你可能感兴趣的:(Java)