git push 時報錯 error: failed to push some refs to 'git@xxxxxx'

原因:這是一個新建的一個倉庫,提交到github時,沒有 pull下來,導致 github中的README.md文件不在本地代碼目錄中

$ git push -u  origin master
To github.com:Houttuyniae/notes.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:Houttuyniae/notes.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

需要先執行 git pull --rebase origin master 把 README.md 下來

$ git pull --rebase origin master
From github.com:Houttuyniae/notes
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
如果在你pull之前,又執行了commit,提交了一次,則會報錯

$ git pull --rebase origin master
error: cannot pull with rebase: You have unstaged changes.
error: additionally, your index contains uncommitted changes.
error: please commit or stash them.
需要先執行 git stash 緩存一下 最後在 push

$ git push -u  origin master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 590 bytes | 590.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To github.com:Houttuyniae/notes.git
   d81c6a9..929dc11  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章