Git push rejected “non-fast-forward”

后端 未结 12 1513
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 02:01

I am fairly new to git yet currently using it to manage our code in a team environment. I had some rebasing issues and I fixed them using

git ch         


        
12条回答
  •  -上瘾入骨i
    2020-11-30 02:34

    I'm late to the party but I found some useful instructions in github help page and I wanted to share them here.

    Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused.

    If another person has pushed to the same branch as you, Git won't be able to push your changes:

    $ git push origin master
    To https://github.com/USERNAME/REPOSITORY.git
     ! [rejected]        master -> master (non-fast-forward)
    error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes (e.g. 'git pull') before pushing again.  See the
    'Note about fast-forwards' section of 'git push --help' for details.
    

    You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:

    $ git fetch origin
    # Fetches updates made to an online repository
    $ git merge origin YOUR_BRANCH_NAME
    # Merges updates made online with your local work
    

    Or, you can simply use git pull to perform both commands at once:

    $ git pull origin YOUR_BRANCH_NAME
    # Grabs online updates and merges them with your local work
    

提交回复
热议问题