Push code: Updates were rejected because the tip of your current branch is behind

Source: Internet
Author: User
Because the commit was just a few days into the merge, and then there was an error in the push code:


$ Git push-u origin update-docs (branch name)
To Git@github.com:******/demo.git
! [Rejected] Master-> Master (Non-fast-forward)
Error:failed to push some refs to ' git@github.com:******/demo.git '
Hint:updates were rejected because the tip of your current branch is behind
Hint:its remote counterpart. Merge the remote changes (e.g. ' git pull ')
Hint:before pushing again.
Hint:see the ' about Fast-forwards ' in ' git push--help ' for details.

Online search, because the remote repository and my local repository conflict caused, and I created a version of the library, in the GitHub version of the library page clicked on the Create Readme.md file button to create a description document, but not pull to the local. This creates a problem with version conflicts.

There are several solutions:

1. Use the forced Push method:

$ Git push-u origin uodate-name-f

This can make remote modifications lost, generally undesirable, especially when many people collaborate on development.

2.push before the remote repository modified pull down

$ GIT pull Origin Update-docs
$ Git push-u origin Update-docs

3. If you do not want to merge remote and local modifications, you can first create a new branch:

$ git branch [name]
and push.

$ Git push-u origin [name]

I feel the second method is the best solution, and the third

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.