一、设置git仓库
1、先删除原来仓库
git remote rm origin
2、添加仓库
git remote add origin [url]
注意:若要修改仓库
git remote origin set-url [url]
二、
在使用Git 配置公司的远程仓库时git push origin master
,出现以下问题
xu:QProj xiaokai$ git push origin master
To https://gitee.com/XXXXX.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/XXXXX.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
从提示语中可以看出是,问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:
(一)、强制推送,即利用强覆盖方式用你本地的代码替代git仓库内的内容,如果远程仓库是刚建的,没有代码,可以这样操作,尽量避免这种操作方法。
git push -f
(二)、
先把git的东西fetch到你本地然后merge后再push
git fetch
git merge
注意:
1、在使用的时候,git merge
,又出现了以下的问题
xu:QProj xiaokai$ git merge
fatal: refusing to merge unrelated histories
对于这个问题。使用
git pull origin master --allow-unrelated-histories
然后继续
git merge
,依然有问题
fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you merge.
这个就好处理了,是我们没有提交当前的变化,
git add .
git commit -m "modify"
然后再来一次
git merge
然后输入
git pull
显示 Already up-to-date.
最后执行
git push origin master
显示文章来源:https://www.toymoban.com/news/detail-795932.html
xu:QProj xiaokai$ git push origin master
Counting objects: 693, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (636/636), done.
Writing objects: 100% (693/693), 2.83 MiB | 570.00 KiB/s, done.
Total 693 (delta 362), reused 0 (delta 0)
remote: Resolving deltas: 100% (362/362), completed with 1 local object.
remote: Powered by Gitee.com
To https://gitee.com/XXXXX.git
83902a5..8100890 master -> master文章来源地址https://www.toymoban.com/news/detail-795932.html
到了这里,关于git 上传出现“ ! [rejected] master -> master (non-fast-forward)”的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!