解决Git出现的常见错误

错误1:

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

解决:

git rm -r --cached ./

git config core.autocrlf false

git add ./

错误2:

Git master branch has no upstream branch

$> 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时一般会上传到origin下的master分支上,然而当repository和branch过多,而又没有设置关联时,git就会产生疑问,因为它无法判断你的push目标。 

解决:

方法一:(远程分支存在的情况才能使用)

# 查看要指向的 repository
git remote -v

# 查看所有分支
git branch -a


git push --set-upstream origin master

# master: 远程branch
# oringin: 在clone远程代码时,git为你创建的指向这个远程代码库的标签,它指向repository。

方法二:根据需要,替换origin和master,此方法的好处是即使远程没有你要关联的分支,它也会自动创建一个出来,以实现关联。

git push -u origin master

错误3:

! [rejected]        master -> master (fetch first)

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@11.111.11.11:bboyHan/golang-data.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first 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.

原因分析:没有同步远程的master

解决:

  git pull origin master

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值