git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git push [rejected] question

From
Jeff King <peff@peff.net>
Date
Feb 19, 2008, 04:33 UTC
Message-ID
<20080219043353.GA23239@sigill.intra.peff.net>
In-Reply-To
<E7DE807861E8474E8AC3DC7AC2C75EE50542F2F1@34093-EVS2C1.exchange.rackspace.com>
On Mon, Feb 18, 2008 at 04:15:01PM -0600, Jason Garber wrote:
> One of our users had this come up today.  He (on a different branch)
> did a push (successfully) earlier today.  Upon pushing some more
> changes this afternoon in the "Task/4919..." branch, the following
> message was received:

I think the user is missing one fundamental aspect of pushing: the behavior of "git push" without any refspecs specified is to push all matching refs (i.e., if you have branch refs/heads/Issue/Default and so does the remote, then it will attempt to push). So no matter what branch he is on when doing the push, it tries to push many such branches.

If you want to push just the current branch, try:
  git push origin HEAD
Show 8 quoted lines
> [caleb@neon VOS4]$ git push
> Enter passphrase for key '/home/caleb/.ssh/id_rsa':
> To ssh://git@code.izrm.com/~/WhiteBoot4/VOS4-NEW
>  ! [rejected]        Issue/Default -> Issue/Default (non-fast forward)
>  ! [rejected]        Issue/Task_4831_MUP_Survey_Layout -> Issue/Task_4831_MUP_Survey_Layout (non-fast forward)
>  ! [rejected]        Task/4872-MUP-APlan-promotion -> Task/4872-MUP-APlan-promotion (non-fast forward)
>  <snip>
> error: failed to push to 'ssh://git@code.izrm.com/~/WhiteBoot4/VOS4-NEW'

These branches are rejected because he has local branches of the same name that are _behind_ where the remote is. In other words, pushing would roll back history, and therefore these pushes are rejected without the '-f' option to force.

These branches get in this state through something like:
  # check out a local branch to match an upstream branch
  git checkout -b Issue/Default origin/Issue/Default
  # now hack on it or whatever
  hack hack hack
  build build build
  # and we're finished, so let's go back to another branch
  git checkout Task/4919...
  # time passes, and somebody else pushes changes to Issue/Default

And now at this point the user's Issue/Default is behind the remote's. Pushing would roll back history, and so is rejected.

> However the branch in question was pushed successfully (despite the error message).
> 
> * Task/4919-MUP-Agent-ID-promotion         7e80ca6
>   origin/Task/4919-MUP-Agent-ID-promotion  7e80ca6

Yes, presumably that was in your <snip> section above. The "error:" message is reported if pushing _any_ branch fails or is rejected. If you are interested in pushing only the one branch, then you need to say so explicitly.

-Peff
Previous: Jason GarberNext: Jay Soffian
Message 2 of 19 in “git push [rejected] question”
  1. Jason GarberFeb 18, 2008
  2. Jeff KingFeb 19, 2008
  3. Jay SoffianFeb 19, 2008
  4. Jeff KingFeb 19, 2008
  5. Jay SoffianFeb 19, 2008
  6. Jeff KingFeb 19, 2008
  7. Johannes SchindelinFeb 19, 2008
  8. push: annoy all users by deprecating the default semanticsJohannes Schindelin, Feb 19, 2008
  9. Jason GarberFeb 19, 2008
  10. Johannes SchindelinFeb 19, 2008
  11. Jeff KingFeb 19, 2008
  12. Johannes SchindelinFeb 19, 2008
  13. Jeff KingFeb 19, 2008
  14. Govind SalinasFeb 20, 2008
  15. Junio C HamanoFeb 20, 2008
  16. Govind SalinasFeb 20, 2008
  17. Junio C HamanoFeb 20, 2008
  18. Jay SoffianFeb 19, 2008
  19. Jeff KingFeb 19, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.