【github出错集合】github分支问题

github常见错误汇总

分支冲突问题

错误:

fatal: Not a valid object name: 'master'.

错误原因:创建仓库时,master主分支存在文件REDME.md文件,git push本地文件发生冲突

klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)

$ 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
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git push --set-upstream origin master
To https://github.com/klauscf/-git.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/klauscf/-git.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.

解决办法:

1.将本地文件先add到本地仓库缓存中,commint到本地仓库。

klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git status
On branch master
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        ME
        Main/
        README.md
        hh.c
nothing added to commit but untracked files present (use "git add" to track)
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git add *
warning: LF will be replaced by CRLF in ME.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory

klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git status
On branch master
No commits yet
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   ME
        new file:   Main/main.c
        new file:   README.md
        new file:   hh.c
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git commit -m '全部文件提交'
[master (root-commit) 7081a85] 全部文件提交
4 files changed, 2 insertions(+)
create mode 100644 ME
create mode 100644 Main/main.c
create mode 100644 README.md
create mode 100644 hh.c
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)

push文件,文件夹不匹配,git报错

klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git push --set-upstream origin master
To https://github.com/klauscf/-git.git
! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/klauscf/-git.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.
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)

2.新建其他分支,并切换到其他分支中去

klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (master)
$ git checkout -b dev
Switched to a new branch 'dev'
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (dev)
$ git push
fatal: The current branch dev has no upstream branch.
To push the current branch and set the remote as upstream, use
    git push --set-upstream origin dev
klaus@klaus MINGW64 /d/CODE/Github/day1/第二次提交测试 (dev)
$ git push -u origin dev
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (5/5), 358 bytes | 119.00 KiB/s, done.
Total 5 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'dev' on GitHub by visiting:
remote:      https://github.com/klauscf/-git/pull/new/dev
remote:
To https://github.com/klauscf/-git.git
* [new branch]      dev -> dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.

分支创建成功,文件上传到dev分支下。

发布了80 篇原创文章 · 获赞 86 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/klaus_x/article/details/83374706