Git 推送拉取报错

今天想把 本地的项目使用 Git 管理推送到码云上边,然后在码云上边建库,建库不要紧,

偏偏手贱的点了创建 README.md 文件(后面解释为什么)

然后本地文件下

初始化仓库

git init

先将本地文件放进 git 管理

git add .

git commit -m "初始仓库"

链接远程仓库

git remote add origin https://gitee.com/null_328_3305/2018xxx.git

然后

git push

报错: 

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

    git push --set-upstream origin master

好吧,根据提示执行

 git push --set-upstream origin master

输入账号,密码

提示失败:

Updates were rejected because the tip of your current branch is behind

远程仓库比本地仓库更新...是因为远程多了一个 README.md 文件,这个时候应该直接删除远程仓库的这个文件就可以的了,偏偏我比较任性就是要这样提交。

拉取远程仓库

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

意思大概就是,当前分支没有跟踪信息,如果这样 现在 push  的话需要指定远程地址

如:git push origin master

提示我们设置默认分支: git branch --set-upstream-to=origin/<branch>(远程分支) master(本地分支)

那我就指定本地 master(默认分支)

执行:

git branch --set-upstream-to=origin/master master

把pull 下来的内容README.md 内容有跟本地冲突内容解决之后,提交

git add .

git commit -m "README.md 冲突解决"

git pull

输入账号密码后提示:

fatal: refusing to merge unrelated histories,

拒绝合并...

原因看采纳的的答案
https://segmentfault.com/q/1010000007730346?_ea=1447694

执行:

git push --allow-unrelated-histories

终于成功....

Counting objects: 6571, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6347/6347), done.
Writing objects: 100% (6571/6571), 269.10 MiB | 353.00 KiB/s, done.
Total 6571 (delta 756), reused 0 (delta 0)

最后提示:

如果需要新建本地仓库链接远程仓库,远程仓库建一个空的就行了,或者建完仓库后 

git clone "仓库地址"

还有,有时候不能太任性了...

简易的命令行入门教程:

Git 全局设置:

git config --global user.name "18y"
git config --global user.email "cmphper@163.com"

创建 git 仓库:

mkdir one
cd one
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin git@gitee.com:null_328_3305/one.git
git push -u origin master

已有仓库?

cd existing_git_repo
git remote add origin git@gitee.com:null_328_3305/one.git
git push -u origin master

 

 

 

 

转载于:https://my.oschina.net/18y/blog/1611202

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值