Search code examples
gitgithubgit-commitgit-pushgit-add

GitHub - error: failed to push some refs to 'git@github.com:myrepo.git'


I ran these commands below:

git add .
git commit -m 't'

Then, when running the command below:

git push origin development

I got the error below:

To git@github.com:myrepo.git
 ! [rejected]        development -> development (non-fast-forward)
error: failed to push some refs to 'git@github.com:myrepo.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.

Are there any ways to solve the error above?


Solution

  • Your origin repository is ahead of your local repository. You'll need to pull down changes from the origin repository as follows before you can push. This can be executed between your commit and push.

    git pull origin development
    

    development refers to the branch you want to pull from. If you want to pull from master branch then type this one.

    git pull origin master