美文网首页
git push 时报错 error: failed to pu

git push 时报错 error: failed to pu

作者: 马威明 | 来源:发表于2020-02-20 14:14 被阅读0次

    新建本地一个仓库,提交到github失败,原因是远程仓库的README.md等文件在push之前,没有 pull下来,导致 github中的远程文件不在本地代码目录中
    报错信息类似如下:

    git push -u  origin master
    To github.com:Houttuyniae/notes.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'git@github.com: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'.
    

    相关文章

      网友评论

          本文标题:git push 时报错 error: failed to pu

          本文链接:https://www.haomeiwen.com/subject/qhdxqhtx.html