使用Git上传项目代码到Gitee遇到的问题1

这篇博客介绍了在使用Git推送项目代码到Gitee时遇到的非快进合并错误。作者详细展示了从提示信息到解决该问题的完整步骤,包括尝试`git pull`,处理不相关的历史记录,最终使用`git push -u origin master -f`强制推送。通过这个过程,读者可以学习如何解决类似Git冲突的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用Git上传项目代码到Gitee遇到的问题

提示错误如下:

$ git push origin master
To gitee.com:chesnyhh/hcsgsal.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:chesnyhh/hcsgsal.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.

解决方法:

$ git pull   //1. 输入git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
    git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
    git branch --set-upstream-to=origin/<branch> master
    
$ git pull origin master  //2. 再输入git pull origin master
From gitee.com:chesnyhh/hcsgsal.git
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

$ git pull origin master --alow-unrelated-histories  //3. 再输入这行

$ git push -u origin master -f   //4. 最后输入这个代码  就可以上传项目代码
Enumerating objects: 105, done.
Counting objects: 100% (105/105), done.
Delta compression using up to 4 threads
Compressing objects: 100% (88/88), done.
Writing objects: 100% (105/105), 154.53 KiB | 1.91 MiB/s, done.
Total 105 (delta 24), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (24/24), done.
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:chesnyhh/hcsgsal.git
 + 8161726...276a37e master -> master (forced update)
Branch 'master' set up to track remote branch 'master' from 'origin'.

完。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值