{"thread":{"id":"40857","subject":"branch --set-upstream-to unexpectedly fails with \"starting point ... is no branch\"","startedAt":"2015-11-23T11:04:50Z","lastAt":"2015-11-25T16:27:50Z","messageCount":5,"participants":["Marc Strapetz","Carlos Martín Nieto"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"273601","messageId":"5652F2D2.3050902@syntevo.com","threadId":"40857","inReplyTo":null,"subject":"branch --set-upstream-to unexpectedly fails with \"starting point ... is no branch\"","fromName":"Marc Strapetz","fromEmail":"marc.strapetz@syntevo.com","sentAt":"2015-11-23T11:04:50Z","receivedAt":"2015-11-23T11:04:50Z","isPatch":false,"sender":{"key":"marc.strapetz@syntevo.com","avatar":"https://avatars.githubusercontent.com/u/3380730?v=4"},"body":"There is a strange \"branch --set-upstream-to\" failure for \"clones\" which \nhaven't been created using \"git clone\" but constructed using \"git init\", \n\"git remote add\" and \"git fetch\".\n\nFollowing script first creates a \"main\" repository and then constructs \nthe clone. Finally, in the clone branches origin/1 and origin/2 will be \npresent, however it's not possible to invoke \"git branch \n--set-upstream-to\" for origin/2 (it works fine for origin/1).\n\nI guess the behavior is related to following line in .git/config:\n\nfetch = refs/heads/1:refs/remotes/origin/1\n\nHowever, I don't understand what's the problem for Git here? Definitely \nthe error \"starting point 'origin/2' is not a branch\" is wrong.\n\n\n\n$ git --version\ngit version 2.5.0.windows.1\n\n$ cd /tmp/gittest\n$ mkdir main\n$ cd main\n$ git init\n$ touch file\n$ git add file\n$ git commit -m \"import\"\n$ git branch 1\n$ git branch 2\n$ git branch\n   1\n   2\n* master\n\n$ cd /tmp/gittest\n$ mkdir clone\n$ cd clone\n$ git init\nInitialized empty Git repository in /tmp/gittest/clone/.git/\n$ git remote add origin /tmp/gittest/main\n$ git config remote.origin.fetch refs/heads/1:refs/remotes/origin/1\n$ git fetch origin\nremote: Counting objects: 3, done.\nremote: Total 3 (delta 0), reused 0 (delta 0)\nUnpacking objects: 100% (3/3), done.\n From /tmp/gittest/main\n  * [new branch]      1          -> origin/1\n\n$ git fetch origin refs/heads/2:refs/remotes/origin/2\n From /tmp/gittest/main\n  * [new branch]      2          -> origin/2\n\n$ git branch --no-track 2 refs/remotes/origin/2\n$ git branch\n   2\n\n# HERE COMES THE STRANGE FAILURE:\n$ git branch --set-upstream-to=origin/2 2\nfatal: Cannot setup tracking information; starting point 'origin/2' is \nnot a branch.\n\n# THIS WORKS AS EXPECTED:\n$ git branch --set-upstream-to=origin/1 2\nBranch 2 set up to track remote branch 1 from origin by rebasing.\n\n-Marc\n"},{"id":"273610","messageId":"15ED3D48-282B-44EF-98C6-EA59F18D633E@dwim.me","threadId":"40857","inReplyTo":"5652F2D2.3050902@syntevo.com","subject":"Re: branch --set-upstream-to unexpectedly fails with \"starting point ... is no branch\"","fromName":"Carlos Martín Nieto","fromEmail":"cmn@dwim.me","sentAt":"2015-11-23T17:04:01Z","receivedAt":"2015-11-23T17:04:01Z","isPatch":false,"sender":{"key":"cmn@dwim.me","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"Hello Mark,\n\nOn 23 Nov 2015, at 12:04, Marc Strapetz <marc.strapetz@syntevo.com> wrote:\n\n> There is a strange \"branch --set-upstream-to\" failure for \"clones\" which haven't been created using \"git clone\" but constructed using \"git init\", \"git remote add\" and \"git fetch\".\n> \n> Following script first creates a \"main\" repository and then constructs the clone. Finally, in the clone branches origin/1 and origin/2 will be present, however it's not possible to invoke \"git branch --set-upstream-to\" for origin/2 (it works fine for origin/1).\n> \n> I guess the behavior is related to following line in .git/config:\n> \n> fetch = refs/heads/1:refs/remotes/origin/1\n> \n> However, I don't understand what's the problem for Git here? Definitely the error \"starting point 'origin/2' is not a branch\" is wrong.\n> \n\nThat is indeed the issue. The configuration which is stored in the configuration is a remote+branch pair. If there is no fetch refspec configured which would create the ‘origin/2’ remote-tracking branch, the command does not know which remote and branch that would correspond to.\n\nIf you had ‘refs/heads/2:refs/remotes/origin/2’ then it would know, but other remote-tracking branches (e.g. ‘origin/3’) would still have an unknown source.\n\nThe error message is indeed bogus; it’s likely one of the functions assuming how it’s going to be used.\n\n   cmn\n"},{"id":"273617","messageId":"56536224.3050306@syntevo.com","threadId":"40857","inReplyTo":"15ED3D48-282B-44EF-98C6-EA59F18D633E@dwim.me","subject":"Re: branch --set-upstream-to unexpectedly fails with \"starting point ... is no branch\"","fromName":"Marc Strapetz","fromEmail":"marc.strapetz@syntevo.com","sentAt":"2015-11-23T18:59:48Z","receivedAt":"2015-11-23T18:59:48Z","isPatch":false,"sender":{"key":"marc.strapetz@syntevo.com","avatar":"https://avatars.githubusercontent.com/u/3380730?v=4"},"body":"On 23.11.2015 18:04, Carlos Martín Nieto wrote:\n> Hello Mark,\n>\n> On 23 Nov 2015, at 12:04, Marc Strapetz <marc.strapetz@syntevo.com> wrote:\n>\n>> There is a strange \"branch --set-upstream-to\" failure for \"clones\" which haven't been created using \"git clone\" but constructed using \"git init\", \"git remote add\" and \"git fetch\".\n>>\n>> Following script first creates a \"main\" repository and then constructs the clone. Finally, in the clone branches origin/1 and origin/2 will be present, however it's not possible to invoke \"git branch --set-upstream-to\" for origin/2 (it works fine for origin/1).\n>>\n>> I guess the behavior is related to following line in .git/config:\n>>\n>> fetch = refs/heads/1:refs/remotes/origin/1\n>>\n>> However, I don't understand what's the problem for Git here? Definitely the error \"starting point 'origin/2' is not a branch\" is wrong.\n>>\n>\n> That is indeed the issue. The configuration which is stored in the configuration is a remote+branch pair. If there is no fetch refspec configured which would create the ‘origin/2’ remote-tracking branch, the command does not know which remote and branch that would correspond to.\n\nThanks, Carlos, I understand now.\n\nMy goal is to have a clone which will only fetch specific branches, so I \nguess I have to stick with \"refs/heads/1:refs/remotes/origin/1\" for the \nbeginning and for every new branch X add another \n\"refs/heads/X:refs/remotes/origin/X\"? Or is there a better way?\n\n-Marc\n"},{"id":"273646","messageId":"12A15BA3-11C2-426A-87D6-421BA9708A51@dwim.me","threadId":"40857","inReplyTo":"56536224.3050306@syntevo.com","subject":"Re: branch --set-upstream-to unexpectedly fails with \"starting point ... is no branch\"","fromName":"Carlos Martín Nieto","fromEmail":"cmn@dwim.me","sentAt":"2015-11-24T16:58:45Z","receivedAt":"2015-11-24T16:58:45Z","isPatch":false,"sender":{"key":"cmn@dwim.me","avatar":"https://avatars.githubusercontent.com/u/335443?v=4"},"body":"\nOn 23 Nov 2015, at 19:59, Marc Strapetz <marc.strapetz@syntevo.com> wrote:\n\n> On 23.11.2015 18:04, Carlos Martín Nieto wrote:\n>> Hello Mark,\n>> \n>> On 23 Nov 2015, at 12:04, Marc Strapetz <marc.strapetz@syntevo.com> wrote:\n>> \n>>> There is a strange \"branch --set-upstream-to\" failure for \"clones\" which haven't been created using \"git clone\" but constructed using \"git init\", \"git remote add\" and \"git fetch\".\n>>> \n>>> Following script first creates a \"main\" repository and then constructs the clone. Finally, in the clone branches origin/1 and origin/2 will be present, however it's not possible to invoke \"git branch --set-upstream-to\" for origin/2 (it works fine for origin/1).\n>>> \n>>> I guess the behavior is related to following line in .git/config:\n>>> \n>>> fetch = refs/heads/1:refs/remotes/origin/1\n>>> \n>>> However, I don't understand what's the problem for Git here? Definitely the error \"starting point 'origin/2' is not a branch\" is wrong.\n>>> \n>> \n>> That is indeed the issue. The configuration which is stored in the configuration is a remote+branch pair. If there is no fetch refspec configured which would create the ‘origin/2’ remote-tracking branch, the command does not know which remote and branch that would correspond to.\n> \n> Thanks, Carlos, I understand now.\n> \n> My goal is to have a clone which will only fetch specific branches, so I guess I have to stick with \"refs/heads/1:refs/remotes/origin/1\" for the beginning and for every new branch X add another \"refs/heads/X:refs/remotes/origin/X\"? Or is there a better way?\n\nIf you want fine-grained control over what gets downloaded, you’ll need to restrict either the configured refspecs or the ones which git-fetch gets.\n\nYou can configure the individual refspecs so a ‘git fetch’ call will download the ones you want, giving you the issue you mention here; or you can configure the default refspec, but always pass explicit instructions to git-fetch, like ‘git fetch refs/heads/1 refs/heads/2’. Newer git versions (past 1.9.3 I think) will update the remote-tracking bracnhes when you do it this way.\n\nBoth of these are annoying in their own way. The second way might be preferable if the fetching is done by a script. But if you absent-mindedly run a lone ‘git fetch’, then you’ll download all branches.\n\nCheers,\n   cmn\n"},{"id":"273742","messageId":"5655E186.8060205@syntevo.com","threadId":"40857","inReplyTo":"12A15BA3-11C2-426A-87D6-421BA9708A51@dwim.me","subject":"Re: branch --set-upstream-to unexpectedly fails with \"starting point ... is no branch\"","fromName":"Marc Strapetz","fromEmail":"marc.strapetz@syntevo.com","sentAt":"2015-11-25T16:27:50Z","receivedAt":"2015-11-25T16:27:50Z","isPatch":false,"sender":{"key":"marc.strapetz@syntevo.com","avatar":"https://avatars.githubusercontent.com/u/3380730?v=4"},"body":"On 24.11.2015 17:58, Carlos Martín Nieto wrote:\n>\n> On 23 Nov 2015, at 19:59, Marc Strapetz <marc.strapetz@syntevo.com> wrote:\n>\n>> On 23.11.2015 18:04, Carlos Martín Nieto wrote:\n>>> Hello Mark,\n>>>\n>>> On 23 Nov 2015, at 12:04, Marc Strapetz <marc.strapetz@syntevo.com> wrote:\n>>>\n>>>> There is a strange \"branch --set-upstream-to\" failure for \"clones\" which haven't been created using \"git clone\" but constructed using \"git init\", \"git remote add\" and \"git fetch\".\n>>>>\n>>>> Following script first creates a \"main\" repository and then constructs the clone. Finally, in the clone branches origin/1 and origin/2 will be present, however it's not possible to invoke \"git branch --set-upstream-to\" for origin/2 (it works fine for origin/1).\n>>>>\n>>>> I guess the behavior is related to following line in .git/config:\n>>>>\n>>>> fetch = refs/heads/1:refs/remotes/origin/1\n>>>>\n>>>> However, I don't understand what's the problem for Git here? Definitely the error \"starting point 'origin/2' is not a branch\" is wrong.\n>>>>\n>>>\n>>> That is indeed the issue. The configuration which is stored in the configuration is a remote+branch pair. If there is no fetch refspec configured which would create the ‘origin/2’ remote-tracking branch, the command does not know which remote and branch that would correspond to.\n>>\n>> Thanks, Carlos, I understand now.\n>>\n>> My goal is to have a clone which will only fetch specific branches, so I guess I have to stick with \"refs/heads/1:refs/remotes/origin/1\" for the beginning and for every new branch X add another \"refs/heads/X:refs/remotes/origin/X\"? Or is there a better way?\n>\n> If you want fine-grained control over what gets downloaded, you’ll need to restrict either the configured refspecs or the ones which git-fetch gets.\n\nThanks, Carlos. I'll take this approach as it's the safer one.\n\n-Marc\n"}]}