Skip to content

Instantly share code, notes, and snippets.

@zhuzhzh
Created August 5, 2017 06:35
Show Gist options
  • Save zhuzhzh/556a9c5617e2fc03c63f8c21755af523 to your computer and use it in GitHub Desktop.
Save zhuzhzh/556a9c5617e2fc03c63f8c21755af523 to your computer and use it in GitHub Desktop.
github_local_push_error.md

提交本地代码到github

提交时出现下面错误

harriszh Sat 14:13@ ~/trunk/vpi$ git push -u origin master
To git@github.com:zhuzhzh/vpiIntro.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:zhuzhzh/vpiIntro.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'Note about
fast-forwards' section of 'git push --help' for details.

错误原因

在提交时,在github上已经有了一个LICENSE的文件 需要把github上的内容先合并才能提交

方法

$ git fetch origin
$ ls
ex1  ex2  ex3  ex4  ex5  README.md
$ git merge origin/master
Merge made by recursive.
 LICENSE |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
 create mode 100644 LICENSE
harriszh Sat 14:25@ ~/trunk/vpi$ git status
# On branch master
nothing to commit (working directory clean)
$ ls
ex1  ex2  ex3  ex4  ex5  LICENSE  README.md
$ git push origin master
Counting objects: 48, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (41/41), done.
Writing objects: 100% (47/47), 10.75 KiB, done.
Total 47 (delta 9), reused 0 (delta 0)
remote: Resolving deltas: 100% (9/9), done.
To git@github.com:zhuzhzh/vpiIntro.git
   70b72f6..b90a785  master -> master

其他注意点

如果安装git后没有设置用户名和email地址,还需要先执行

git config --global user.name "harriszh"
git config --global user.email "zhuzhzh@163.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment