git clone 别人的项目上传到自己的Gitee或者github仓库

git clone别人的项目
git clone https://github.com/wohuweixiya/yft-design.git

进入该项目内,删除原有的.git信息
rm -r .git

初始化.git
git init

将本地代码添加到仓库
git add .

git commit -m "提交仓库说明"

Github上新建一个和这个clone下来的项目名称一样的仓库名,比如你clone下来的这个项目叫my_project,就在Github上新建名为my_project的仓库

关联上远程仓库
git remote add origin 新建的仓库地址

比如:git remote add origin https://gitee.com/username/uniapp-project.git

将代码上传到Github
git push --set-upstream origin master

如果报以下错误:
error: failed to push some refs to 'https://gitee.com/lifexu/uniapp-project.git' hint: Updates were rejected because the remote contains work that you do not hint: have locally. This is usually caused by another repository pushing to hint: the same ref. If you want to integrate the remote changes, use hint: 'git pull' before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.

表示本地仓库和远程仓库的历史没有共同的祖先,Git 默认不允许合并这样的两个仓库。

要解决这个问题,你可以使用 --allow-unrelated-histories 选项来强制 Git 合并这两个不相关的历史。以下是操作步骤:

使用 --allow-unrelated-histories 选项执行 git pull 命令:
git pull origin master --allow-unrelated-histories

如果有合并冲突,你需要手动解决它们,然后创建一个新的提交。

解决完冲突后,再次尝试推送更改到远程仓库:
git push --set-upstream origin master

相关推荐
花花无缺4 小时前
merge与rebase的区别
git
Alex老夫子6 小时前
解决 husky > pre-commit hook failed (add --no-verify to bypass)
git·android studio
漂亮_大男孩10 小时前
Git|GitHub SSH 连接配置与验证全流程(通用方法)
git·ssh·github
灵码未来_official10 小时前
git操作指令
git
唐青枫10 小时前
Git 实战:一文读懂 git push -u origin main 命令
git
Vanranrr11 小时前
Git Commit Message 最佳实践:从一次指针Bug说起
git·bug
___波子 Pro Max.12 小时前
Git删除本地与远程tag操作指南
git
Young_Gnay1 天前
在学校和工作中遇到的一些git用法
git
一路向北_Coding1 天前
Git系列之关联远程仓库
git·github