1

What can I do to fix this? I have added a new branch added changes, and want to push them to a repository. When I do a push I get this message. When I do a pull it says everything is good. So I can pull and all is good but not when I push? Also what is a fast forward update?

error: failed to push some refs to '<repository>'
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.

camdixon@staging2:/var/www/site$ git pull
Username for '<repository>': camdixon
Password for 'username@<repository>': 
Already up-to-date.
camdixon
  • 852
  • 2
  • 18
  • 33

1 Answers1

3

When you run git pull, you are doing a fetch followed by a merge (or a fetch followed by a rebase), as noted in What is the difference between 'git pull' and 'git fetch'?.

This merges (or rebases) a single branch, namely your current branch.

Note that before your Git printed this complaint (I have bolded significant words):

error: failed to push some refs to '<repository>' 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.

it will also have printed which refs failed to be pushed, and which ones succeeded.

When you run git push, you are pushing potentially many references: you might push 17 branches and 3 tags, for instance, for a total of 20 references being pushed, all at once. If your current branch is good, but all 16 others fail, you would generally see one success and 16 failure notices there. If the three tags succeeded you would see 3 additional success notices for those tags.

If all the updates that failed are not particularly interesting to you, you can ignore them. If the one(s) you care about was (or were) not listed in the successes, you will need to retry.

See Default behavior of "git push" without a branch specified and "simple" vs "current" push.default in git for decentralized workflow for instructions on configuring which branch(es) are pushed by default.

To push one specific branch, regardless of whatever your default is set to, list that branch on the command line:

git push origin razzle-dazzle-branch

If this is the very first push of a branch, so that this will create the branch in the remote repository (origin in this example), you may want to add the -u flag:

git push -u origin razzle-dazzle-branch

which will tell your Git to set origin/razzle-dazzle-branch as the upstream for your razzle-dazzle-branch, provided the push of razzle-dazzle-branch succeeds.

... what is a fast forward update?

See just about any of the answers that turn up in a google query for git fast forward update site:stackoverflow.com, such as What does "Git push non-fast-forward updates were rejected" mean?.

Community
  • 1
  • 1
torek
  • 448,244
  • 59
  • 642
  • 775