解决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

 

展开阅读全文

没有更多推荐了,返回首页