简体   繁体   中英

git cannot push to master branch

  1. git repostory in github contains below branches (master,'abc' )
  2. clone git repo abc branch to local machine
  3. go inside to the repo folder using git bash
  4. create git branch called bbb
  5. checkout to the branch bbb
  6. add files to repo folder
  7. commit the changes
  8. push changes to the remote repo abc branch used this command:

     git push origin bbb:abc 

    It works fine.

  9. then going to push changes to the remote repo master branch used this command:

     git push origin bbb:master 

Then the below error message comes:

 ! [rejected]        bbb -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/sw7x/testing4.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Can anybody explain why this happens?

As git itself said:

hint: (e.g. 'git pull ...') before pushing again.

first pull (or even fetch ) from master, do the required changes and finally push . If you're a mean person and do NOT care about other people changes, you can use push -f to force the push.

The reason you get this error is that your local version is different from the version resides in github repo and you should reconcile those two somehow to be able to push your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM