Reputation: 171409
My current branch is my_branch
. Trying to push the changes to the remote repo I get:
$ git push
Counting objects: 544, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (465/465), done.
Writing objects: 100% (533/533), 2.04 MiB | 1.16 MiB/s, done.
Total 533 (delta 407), reused 0 (delta 0)
To [email protected]
4ed90a6..52673f3 my_branch -> my_branch
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]'
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.
Trying to git pull
results in:
$ git pull
Already up-to-date.
Why I get this error?
How could I resolve this problem and perform git push
successfully?
Upvotes: 26
Views: 106597
Reputation: 369
Specifying the exact branch to pull using
git pull some_origin some_branch
might help. I was on some_branch
, and git pull
without the extra info wouldn't pull some_branch
, although it was checked out. Without having pulled correctly, a git push
was naturally rejected.
However, this is not intended behavior. The likely cause was an unconventional git configuration for dot files, with the work tree and git directory separated.
Upvotes: 0
Reputation: 2141
It could also be a Git Hook! That would give the same error.
Git Hooks run locally, so they can intercept and "pre-process" your commits before they are pushed.
More on Git Hooks here: https://githooks.com/
You should be able to find the hooks in the root of your repo, here: .git/hooks
.
Reading through the hook files may or may not not be helpful; they are full of advanced git commands and regexp.
Use File Explorer/Finder to look, as files prefixed by a period (.git, .gitignore) are often hidden in IDE's.
I got this same error when trying to push a branch called feature/JIRA-123_description-text
, and after some looking around I discovered that all the other project branches were named features/...
, so I was just missing an s in the word features. Renaming the branch fixed it.
So, in case pulling master etc does not fix the issue, try looking at some other branch names and match the format. Or check docs to see if there are special branch naming policies, or if you've tried to push something in the wrong file format et cetera.
Upvotes: 3
Reputation: 851
what solved it for me:
go to https://github.com/settings/emails
unckeck: "Block command line pushes that expose my email"
the issue for me was: I had my email in the license
Upvotes: 2
Reputation: 8490
[If your master branch is already configured to rebase on pull, then you just need to do a pull on the master branch as is described in other answerd, but otherwise:]
If you get a non-fast-forward message, this means you can only push commits on top of the existing commits, but you're trying to do otherwise. Do a rebase on master before pushing (assuming the remote is called origin):
git checkout master
git pull --rebase origin master
git push
See also this question: git rebase and git push: non-fast forward, why use?
Upvotes: 11
Reputation: 239402
My current branch is my_branch.
That is your problem. When you pull, Git is telling you that your branch my_branch
is up to date, not master
, which is behind origin/master
making a fast-forward merge impossible.
In order to push master, you need to check out master
and pull. This will merge in the changes waiting on origin/master
and allow you to push your own changes.
git checkout master
git pull
# resolve conflicts, if any
git push
Upvotes: 36