本地项目上传至gitlab

前提

        gitlab上新建同名项目,复制项目地址,本地打开git命令工具:git bash here

1.设置仓库地址

git remote add origin http://66.10.111.43:82/zxpt/zxpt.git

若报错:

fatal: not a git repository (or any of the parent directories): .git


        说明本地项目没有初始化

报错:

The file will have its original line endings in your working directory

解决:

    git rm -r --cached .  // 注意 这里是有 "." 的,  ". " 代表当前目录

    git config core.autocrlf false

原因:

        从别人github仓库地址上通过git clone下载下来,带有原git信息

2.项目初始化

git init

3.切换分支

git fetch

git branch -m master main

4.拉代码

git pull --rebase origin main

报错:

From http://66.10.111.43:82/zxpt/zxpt
 * branch            main       -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
        README.md
Please move or remove them before you merge.
Aborting

解决:

git merge origin FETCH_HEAD

5.将代码添加到临时存储

git add .

6.提交代码

git commit -m "初始化"

7.推送代码

git push -f

报错:

fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin main

解决:

git push --set-upstream origin main

报错:

To http://66.10.111.43:82/zxpt/zxpt.git
 ! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'http://66.10.111.43:82/zxpt/zxpt.git'

解决:

git fetch origin main

git merge origin FETCH_HEAD

git pull origin main

git pull --rebase origin main

再执行:

git push --set-upstream origin main

推送语句:

git push -f


 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值