git移除现有远程仓库文件和提交记录

背景

公司gitlab新建仓库权限被关了

自己有项目想要找个服务器仓库托管,刚好服务器上有个自己之前存在的没用的仓库,所以想要清掉它把现在自己本地的git仓库push上去

操作

step1. 清掉现有仓库

找个空文件夹,将你想要托管的仓库.gitignore文件加入初始化一个新仓库,并push到服务器上没用的仓库里

git init
git add -A
git commit -m "init repo"
git remote add origin <remoteRepoUrl>
git push -f --set-upstream origin master

push时如果报错:      “remote: GitLab: You are not allowed to force push code to a protected branch on this project.”

是因为远程仓库的master分支设置了为保护分支,可以通过在远程仓库的Settings-Repository-Protected Branches将master改为unprotect,再重新执行push命令即可。

step2. 将想要托管的本地仓库修改remote后push上去

git remote rm origin
git remote add origin <remoteRepoUrl>
git push -f --set-upstream origin master

 

posted @ 2023-12-04 16:22  蛮哥哥  阅读(58)  评论(0编辑  收藏  举报