Gitee更换git路径,上传已有本地项目

前提描述

项目原先有git路径,并且原路径炸时,本地有修改的代码没有提交,并且不在master分支上,现需要更换项目的git路径

更换路径步骤

1.我用的gitee,登录账户,新建仓库

在这里插入图片描述

2. 填写相关信息

在这里插入图片描述

  1. 先把本地分支的代码都合并到本地的master分支上,在本地文件夹,cmd打开明令行窗口
1.更新git路径 参考:https://www.jianshu.com/p/3380ec281729
【 git remote set-url origin https://gitee.com/fi**nt1.git 】
或
【
git remote rm origin
git remote add origin https://gitee.com/**.git
】

2.查看分支
# 查看本地分支
git branch

# 查看远程分支 (发现都是之前git路径的远程分支)
git branch -r

3.刷新分支,更新远程分支(得到当前git路径的分支)
git remote update origin --prune

4.这时候发现代码已经push到远程了
(命令的意思是,本地有master,远程没有,执行后,远程会创建master,并建立本地master和远程master的关联关系,也将本地master代码push到远程master分支上)
git push --set-upstream origin master(远程分支名)
or
git branch --set-upstream-to=origin/master master

【
插曲:
如果在创建仓库的时候,勾选了(初始化Readme),这时候仓库是自动创建两个文件,从本地提交代码到远程会出问题,原因是push上去的时候,仓库内容和本地内容已经不一样
E:\WebSni>git push -u origin master
To https://gitee.com/fightinghh/mole-mini-wx-front.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/fightinghh/mole-mini-wx-front.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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 pull --rebase origin master
然后再git push origin master

或者粗暴点,直接重建个空仓库,不要创建Readme文件,按上面的步骤上传代码
】

5.然后需要什么其他的分支再去创建

建议同步完代码再创建
在这里插入图片描述

参考链接

git操作常用代码-https://blog.csdn.net/weixin_58276266/article/details/122224653
更改git路径-https://blog.csdn.net/weixin_42526326/article/details/121156911

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐