Git Upload to Branch Error: Failed to Push Some Refs

Kitten in a shoe

On larger Git projects, I often meet the post-obit scenario play out after someone'southward done some work and is ready to push information technology to the remote repo:

...making and committing changes to "develop" branch...
$ git pull
Already up-to-date.
$ git push
Counting objects: v, done.
Delta compression using upward to viii threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 363 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@github.com:examination-repo/test_repo.git
e8c1210..1a0c4d4  develop -> develop
! [rejected]        new_feature -> new_feature (non-fast-forward)
mistake: failed to push some refs to 'git@github.com:test-repo/test_repo.git'
To prevent you from losing history, non-fast-forrad updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing over again. See the
'Notation well-nigh fast-forrad' section of 'git button --assistance' for details.



What happened? They did the right affair and pulled before pushing, simply they're getting an error nearly being out of appointment. Running git pull again gives Already upwards-to-date once more, merely then pushing still gives the same mistake. What gives?

This isn't actually an mistake. By default, git push attempts to push button every local branch with a matching remote branch. The error message stems from other locally-copied branches being out of date. In the above "error" bulletin, you can see that the develop push button really worked correctly, only the push of the new_feature branch failed (every bit information technology should, every bit it'southward out of engagement).

There are a few options for handling this "error":

  • Checkout and pull each branch
    This is a bad pick. Don't do this. I only mention information technology considering it's what the mistake message unhelpfully suggests. This is the solution when the branch you're interested in pushing is out of appointment, not in this instance.
  • Ignore it
    The branch existence worked on was pushed correctly, so this message can be safely ignored.  Still, yous take to check that information technology was other branches causing the message and not that your copy of the branch y'all're working on is out of appointment.
  • Use git push button origin develop instead
    You can fully specify which remote and which co-operative should be pushed, avoiding any ambiguity. A downside is that approximately 100% of git repos in the wild have only one remote and thus specifying origin often becomes mere cargo-cult practice without any understanding as to why information technology'due south necessary. Having to specify the branch too seems superfluous; when was the last time yous did some work on a branch and so decided to button some other branch?
  • Configure git more sensibly: git config --global button.default upstream
    Instead of attempting to push all matching branches, setting push.default to upstream volition only push the current co-operative to its matching upstream branch. Why this isn't the default is across me. For more information, see the man page for git config.

To my mind, git push button should mirror git pull in only affecting the current co-operative. Setting it up to require more specificity or actress configuration to achieve that behavior might be useful in the rarefied world of Linux kernel development, but for anybody else using git this manner makes more than sense.


Postscript: On the joys of git'southward documentation
Question, what does the documentation say git push button (without any arguments) does?

$ git push --help  ...snip 90% of man folio all the way to the EXAMPLES section...         git push            Works similar git push <remote>, where <remote> is the current            co-operative'southward remote (or origin, if no remote is configured for the            current branch).  # Okay, and so it's equivalent to 'git push origin', what'southward that do?         git push origin            Without additional configuration, works like git push origin :.  # Okay...         git push origin :            Push "matching" branches to origin. See <refspec> in the OPTIONS            department higher up for a clarification of "matching" branches.  # Sigh  OPTIONS        ...snip <repository> paragraph...        <refspec>...            ...snip vi paragraphs...            The special refspec : (or +: to allow not-fast-forward updates)            directs git to push "matching" branches: for every branch that            exists on the local side, the remote side is updated if a branch of            the same name already exists on the remote side.  # There we have information technology.  After starting from virtually the finish of the documentation, and traversing three levels of indirection, we've determined what the most basic form of the control does.  What could exist easier!                  

mcelroysuirly.blogspot.com

Source: https://blog.grio.com/2012/05/preventing-spurious-error-failed-to-push-some-refs-messages-from-git.html

0 Response to "Git Upload to Branch Error: Failed to Push Some Refs"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel