{"thread":{"id":"60480","subject":"git refusing to merge branches when pulling using a refspec","startedAt":"2023-11-06T17:44:06Z","lastAt":"2023-11-06T23:38:55Z","messageCount":2,"participants":["Santiago García Pimentel","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"484470","messageId":"FC0625CD-D736-412C-A4C5-04F9F41FFEEA@garciapimentel.com","threadId":"60480","inReplyTo":null,"subject":"git refusing to merge branches when pulling using a refspec","fromName":"Santiago García Pimentel","fromEmail":"santiago@garciapimentel.com","sentAt":"2023-11-06T17:36:45Z","receivedAt":"2023-11-06T17:44:06Z","isPatch":false,"sender":{"key":"santiago@garciapimentel.com","avatar":null},"body":"Hello,\n\nI'm dealing with a small automation (CI) to synchronise some specific branches between two git repositories.\n\nI need to sync a branch with other using a user-given refspec. e.g.\n\n$ git pull origin \"refs/heads/branchOrigin:refs/heads/branchDestination”.\n\n(I’ll have a list of refspecs, but so far Im trying to make it work with one)\n\nWhen the branch can be fast-forwarded there is no problem, but I cannot manage to make it work when it cant.\n\nI just. get the message \"[rejected] branchOrigin -> branchDestination (non-fast forward).\"\n\nI've tried  the following:\n- adding a git config with pull.rebase=false  (I also tried true)\n- adding --no-rebase to the pull command  (I also tried —rebase)\n\nIn any cases the result is the same\n\nThe issue is, It does work if I just pass the branch names. e.g.\n\ngit pull origin branchOrigin --no-edit\n\nmerges the branch just fine\n\nIm not sure why git refuses to merge the branches when I pass a full refspec. is this intentional? is there some other incantation I need to use to make this work?\n\nThank you!\n\nSantiago García Pimentel.\nsantiago@garciapimentel.com"},{"id":"484483","messageId":"xmqqbkc6cv07.fsf@gitster.g","threadId":"60480","inReplyTo":"FC0625CD-D736-412C-A4C5-04F9F41FFEEA@garciapimentel.com","subject":"Re: git refusing to merge branches when pulling using a refspec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-11-06T23:38:48Z","receivedAt":"2023-11-06T23:38:55Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Santiago García Pimentel <santiago@garciapimentel.com> writes:\n\n> Hello,\n>\n> I'm dealing with a small automation (CI) to synchronise some specific branches between two git repositories.\n>\n> I need to sync a branch with other using a user-given refspec. e.g.\n>\n> $ git pull origin \"refs/heads/branchOrigin:refs/heads/branchDestination”.\n>\n> (I’ll have a list of refspecs, but so far Im trying to make it work with one)\n>\n> When the branch can be fast-forwarded there is no problem, but I cannot manage to make it work when it cant.\n>\n> I just. get the message \"[rejected] branchOrigin -> branchDestination (non-fast forward).\"\nWith the \"pull\" command above, you are doing two logically\nindependent things.  Do you really need to do both?\n\n * git pull \"<remote>\" \"<src>:<dst>\" first does a \"git fetch\" to\n   locally update <dst> with the commit that is pointed at by <src>\n   at the <remote> repository.\n\n * then, into the currently checked out HEAD, the <src> taken from\n   <remote> is merged into.\n\nIf you do not need to update <dst> locally, don't give :<dst> part\non the command line.\n\nIf you do need to update <dst> locally and safely, then thank that\nyou got the [rejected] message.  Because the <src> was updated at\nthe <remote> side that is not based on what you have at <dst>\nlocally, you may be losint commits from your local <dst> if you let\nthe first stage of the \"git pull\" go through, and that is what the\nfailing command is about.\n\nIf you do need to update <dst> locally but you do not have anything\nvaluable on <dst> locally (in other words, <dst> is used only to\nkeep track of <src> at <remote>, and if <remote> rewinds the history\nof their <src> and loses some commits, you want to lose these commits\nthe same way from your <dst>), then add \"+\" before the refspec, i.e.\n\n    git pull \"<remote>\" \"+<src>:<dst>\"\n\n"}]}