{"thread":{"id":"32365","subject":"How to specify remote branch correctly","startedAt":"2012-12-17T02:30:00Z","lastAt":"2012-12-17T07:41:33Z","messageCount":11,"participants":["Woody Wu","Andrew Ardill","Tomas Carnecky","Chris Rorvick"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"204999","messageId":"slrnkct0r3.dsp.narkewoody@zuhnb712.local.com","threadId":"32365","inReplyTo":null,"subject":"How to specify remote branch correctly","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-17T02:30:00Z","receivedAt":"2012-12-17T02:30:00Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"Hi, List\n\nI have two branches in the remote, say, origin/master, origin/foo.  Then\nwhen I tried to switch to the remote foo branch, the following two\nmethods gave me different results:\n\n1. git checkout foo\n2. git checkout origin/foo\n\nThe first method run silently with success, but the second method\ncomplains that I got a 'detached HEAD'.  So, I think I don't understand\nthe difference between 'foo' and 'origin/foo'.  Can someone give me a\nhint?\n\nSupposing I have another remote defined in .git/config that points\nto another repository but also have a same name branch, say\n'remote-x/foo', how do I tell git which 'foo' I want to switch to?\n\nThe similar problem also exists for 'fetch' command to me.  From the man\npage, I don't find answer of how to specify which remote I am going to\nfetch from. Can you help me?\n\nThanks in advance.\n\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205001","messageId":"CAH5451=7frqa-YHXubvO=dMK2CvVoWR-VFZ3XCmKouNiQz4gAg@mail.gmail.com","threadId":"32365","inReplyTo":"slrnkct0r3.dsp.narkewoody@zuhnb712.local.com","subject":"Re: How to specify remote branch correctly","fromName":"Andrew Ardill","fromEmail":"andrew.ardill@gmail.com","sentAt":"2012-12-17T04:27:46Z","receivedAt":"2012-12-17T04:27:46Z","isPatch":false,"sender":{"key":"andrew.ardill@gmail.com","avatar":"https://gravatar.com/avatar/da14cb7c091dd44dc6c63a4d3361b149acaf25226dc78eb4131a17b93d9b0993?d=mp&s=160"},"body":"On 17 December 2012 13:30, Woody Wu <narkewoody@gmail.com> wrote:\n> 1. git checkout foo\n> 2. git checkout origin/foo\n>\n> The first method run silently with success, but the second method\n> complains that I got a 'detached HEAD'.  So, I think I don't understand\n> the difference between 'foo' and 'origin/foo'.  Can someone give me a\n> hint?\n\nHi Woody,\n\nI think you are just missing a couple of important distinctions that\ngit makes about the different references that exist in your\nrepository.\n\nA remote reference (origin/foo) describes exactly the state of\nsomebody else's branch at the time you last synchronised with them. It\ndoes not make sense for you to be able to 'edit' this state, as it\ndoesn't belong to you. Instead, we create a copy of that reference and\ngive it a name (git checkout foo origin/foo) and call this a local\nreference (foo). Git then provides machinery around keeping these in\nsync with each other (git branch --set-upstream foo origin/foo) but we\ndon't _have_ to keep these in sync at all! In fact, the names can be\ncompletely arbitrary and we don't have to track the upstream at all.\n\nIf I have some other remote (remote-x) that has the same branch as\norigin but with some other changes I want to look at, we can just\ncheck that out to another branch (git checkout remote-x-foo\nremote-x/foo), or simply download it as a remote ref and merge the\nchanges on top of my existing local branch (git fetch remote-x; git\ncheckout foo; git merge remote-x/foo).\n\nThere are lots of patterns that can emerge from this functionality,\nbut the main thing to remember is that to create changes on top of a\nremote branch, we first need to create a local copy of it. A 'detached\nHEAD' here means that we are looking at the remote repository's branch\nbut don't have a local copy of it, so any changes we make might be\n'lost' (that is, not have an easy to find branch name).\n\nRegards,\n\nAndrew Ardill\n"},{"id":"205005","messageId":"slrnkcta0j.mlu.narkewoody@zuhnb712.local.com","threadId":"32365","inReplyTo":"CAH5451=7frqa-YHXubvO=dMK2CvVoWR-VFZ3XCmKouNiQz4gAg@mail.gmail.com","subject":"Re: How to specify remote branch correctly","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-17T05:06:33Z","receivedAt":"2012-12-17T05:06:33Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"On 2012-12-17, Andrew Ardill <andrew.ardill@gmail.com> wrote:\n> On 17 December 2012 13:30, Woody Wu <narkewoody@gmail.com> wrote:\n>> 1. git checkout foo\n>> 2. git checkout origin/foo\n>>\n>> The first method run silently with success, but the second method\n>> complains that I got a 'detached HEAD'.  So, I think I don't understand\n>> the difference between 'foo' and 'origin/foo'.  Can someone give me a\n>> hint?\n>\n> Hi Woody,\n>\n> I think you are just missing a couple of important distinctions that\n> git makes about the different references that exist in your\n> repository.\n>\n> A remote reference (origin/foo) describes exactly the state of\n> somebody else's branch at the time you last synchronised with them. It\n> does not make sense for you to be able to 'edit' this state, as it\n> doesn't belong to you. Instead, we create a copy of that reference and\n> give it a name (git checkout foo origin/foo) and call this a local\n> reference (foo). Git then provides machinery around keeping these in\n> sync with each other (git branch --set-upstream foo origin/foo) but we\n> don't _have_ to keep these in sync at all! In fact, the names can be\n> completely arbitrary and we don't have to track the upstream at all.\n>\n> If I have some other remote (remote-x) that has the same branch as\n> origin but with some other changes I want to look at, we can just\n> check that out to another branch (git checkout remote-x-foo\n> remote-x/foo), or simply download it as a remote ref and merge the\n> changes on top of my existing local branch (git fetch remote-x; git\n> checkout foo; git merge remote-x/foo).\n\nThanks for explaining the concept of branch to me.  Now I understood the\ndifference between local and remote branch.  But I still have\ndifficulties in answering my own questions.\n\n1. git checkout foo.\nBy this command, I think I am checking out files in my local branch\nnamed foo, and after that I also switch to the branch. Right?\n\n2. git checkout origin/foo\nBy this command, I am checking out files in remote branch origin/foo,\nbut don't create a local branch, so I am not in any branch now. This is\nthe reason why git tell me that I am in a 'detached HEAD'. Is this\nunderstanding right?\n\n>\n> There are lots of patterns that can emerge from this functionality,\n> but the main thing to remember is that to create changes on top of a\n> remote branch, we first need to create a local copy of it. A 'detached\n> HEAD' here means that we are looking at the remote repository's branch\n> but don't have a local copy of it, so any changes we make might be\n> 'lost' (that is, not have an easy to find branch name).\n>\n\nI think here is a little confuse to me.  You mean that a 'detached HEAD'\nmeans I don't have a local copy, but I remember that if I run something\nlike:\n    $ git checkout a-tag-name\nthen I ususally went into 'detached HEAD' but my local files really get\nswitched to those files in the tag 'a-tag-name'.  So what does you mean\nby 'don't have a local copy'?\n\nMany thanks!\n\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205006","messageId":"CAH5451kmTW+nO4V4pjSdaqhHAb=RX-tawLo=rJfuPnDRDWeSEA@mail.gmail.com","threadId":"32365","inReplyTo":"slrnkcta0j.mlu.narkewoody@zuhnb712.local.com","subject":"Re: How to specify remote branch correctly","fromName":"Andrew Ardill","fromEmail":"andrew.ardill@gmail.com","sentAt":"2012-12-17T05:13:08Z","receivedAt":"2012-12-17T05:13:08Z","isPatch":false,"sender":{"key":"andrew.ardill@gmail.com","avatar":"https://gravatar.com/avatar/da14cb7c091dd44dc6c63a4d3361b149acaf25226dc78eb4131a17b93d9b0993?d=mp&s=160"},"body":"On 17 December 2012 16:06, Woody Wu <narkewoody@gmail.com> wrote:\n> 1. git checkout foo.\n> By this command, I think I am checking out files in my local branch\n> named foo, and after that I also switch to the branch. Right?\n\nCorrect. Your working directory (files) switch over to whatever your\nlocal branch 'foo' points to, and your HEAD is updated to point to\nyour local branch 'foo'. Unless something goes wrong/you have\nconflicting files/uncommitted changes etc.\n\n> 2. git checkout origin/foo\n> By this command, I am checking out files in remote branch origin/foo,\n> but don't create a local branch, so I am not in any branch now. This is\n> the reason why git tell me that I am in a 'detached HEAD'. Is this\n> understanding right?\n\nCorrect! Your working directory is updated, however it doesn't make\nsense for you to make changes to a remote branch, so HEAD is updated\nto be detached.\n\n>>\n>> There are lots of patterns that can emerge from this functionality,\n>> but the main thing to remember is that to create changes on top of a\n>> remote branch, we first need to create a local copy of it. A 'detached\n>> HEAD' here means that we are looking at the remote repository's branch\n>> but don't have a local copy of it, so any changes we make might be\n>> 'lost' (that is, not have an easy to find branch name).\n>>\n>\n> I think here is a little confuse to me.  You mean that a 'detached HEAD'\n> means I don't have a local copy, but I remember that if I run something\n> like:\n>     $ git checkout a-tag-name\n> then I ususally went into 'detached HEAD' but my local files really get\n> switched to those files in the tag 'a-tag-name'.  So what does you mean\n> by 'don't have a local copy'?\n\nI should have been more clear. Here I mean that you don't have a local\ncopy of the branch reference. Your working directory is updated to be\nin sync with the remote branch, but you haven't yet copied that remote\nreference to a local branch that you can update with your changes.\n\nHope that clears it up.\n\nRegards,\n\nAndrew Ardill\n"},{"id":"205008","messageId":"1355722245-ner-6603@calvin","threadId":"32365","inReplyTo":"CAH5451kmTW+nO4V4pjSdaqhHAb=RX-tawLo=rJfuPnDRDWeSEA@mail.gmail.com","subject":"Re: How to specify remote branch correctly","fromName":"Tomas Carnecky","fromEmail":"tomas.carnecky@gmail.com","sentAt":"2012-12-17T05:30:45Z","receivedAt":"2012-12-17T05:30:45Z","isPatch":false,"sender":{"key":"tomas.carnecky@gmail.com","avatar":null},"body":"On Mon, 17 Dec 2012 16:13:08 +1100, Andrew Ardill <andrew.ardill@gmail.com> wrote:\n> On 17 December 2012 16:06, Woody Wu <narkewoody@gmail.com> wrote:\n> > 1. git checkout foo.\n> > By this command, I think I am checking out files in my local branch\n> > named foo, and after that I also switch to the branch. Right?\n> \n> Correct. Your working directory (files) switch over to whatever your\n> local branch 'foo' points to, and your HEAD is updated to point to\n> your local branch 'foo'. Unless something goes wrong/you have\n> conflicting files/uncommitted changes etc.\n\n'git checkout foo' has special meaning if a local branch with that name\ndoesn't exist but there is a remote branch with that name. In that case it's\nequivalent to: git checkout -t -b foo origin/foo. Because that's what people\nusually want.\n"},{"id":"205009","messageId":"CAH5451=KX5eZH6AUoaQ7YcWcNcKhUp8Lk8Uvs3o=jWW=vaYiCg@mail.gmail.com","threadId":"32365","inReplyTo":"1355722245-ner-6603@calvin","subject":"Re: How to specify remote branch correctly","fromName":"Andrew Ardill","fromEmail":"andrew.ardill@gmail.com","sentAt":"2012-12-17T05:52:52Z","receivedAt":"2012-12-17T05:52:52Z","isPatch":false,"sender":{"key":"andrew.ardill@gmail.com","avatar":"https://gravatar.com/avatar/da14cb7c091dd44dc6c63a4d3361b149acaf25226dc78eb4131a17b93d9b0993?d=mp&s=160"},"body":"On 17 December 2012 16:30, Tomas Carnecky <tomas.carnecky@gmail.com> wrote:\n> 'git checkout foo' has special meaning if a local branch with that name\n> doesn't exist but there is a remote branch with that name. In that case it's\n> equivalent to: git checkout -t -b foo origin/foo. Because that's what people\n> usually want.\n\nThis is true, but I don't think it is documented. Does anyone know if\nthis is documented anywhere in particular? The git checkout man pages\nseem to not mention it, and the git branch page doesn't seem to\nmention it either, but perhaps I am just missing it?\n\nIn any case, might be useful to make this behaviour more clear.\n\nRegards,\n\nAndrew Ardill\n"},{"id":"205010","messageId":"CAEUsAPY3rbwrN48v5oM1OsA9ftaaWPQC69XO75ug=Ev55N7NEg@mail.gmail.com","threadId":"32365","inReplyTo":"CAH5451=KX5eZH6AUoaQ7YcWcNcKhUp8Lk8Uvs3o=jWW=vaYiCg@mail.gmail.com","subject":"Re: How to specify remote branch correctly","fromName":"Chris Rorvick","fromEmail":"chris@rorvick.com","sentAt":"2012-12-17T06:44:36Z","receivedAt":"2012-12-17T06:44:36Z","isPatch":false,"sender":{"key":"chris@rorvick.com","avatar":"https://avatars.githubusercontent.com/u/824726?v=4"},"body":"On Sun, Dec 16, 2012 at 11:52 PM, Andrew Ardill <andrew.ardill@gmail.com> wrote:\n> This is true, but I don't think it is documented.\n\nI noticed this, too.  I was just about to send a patch to add this.\n\nChris\n"},{"id":"205014","messageId":"slrnkctg0k.mmj.narkewoody@zuhnb712.local.com","threadId":"32365","inReplyTo":"CAH5451kmTW+nO4V4pjSdaqhHAb=RX-tawLo=rJfuPnDRDWeSEA@mail.gmail.com","subject":"Re: How to specify remote branch correctly","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-17T06:48:57Z","receivedAt":"2012-12-17T06:48:57Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"On 2012-12-17, Andrew Ardill <andrew.ardill@gmail.com> wrote:\n> On 17 December 2012 16:06, Woody Wu <narkewoody@gmail.com> wrote:\n>> 1. git checkout foo.\n>> By this command, I think I am checking out files in my local branch\n>> named foo, and after that I also switch to the branch. Right?\n>\n> Correct. Your working directory (files) switch over to whatever your\n> local branch 'foo' points to, and your HEAD is updated to point to\n> your local branch 'foo'. Unless something goes wrong/you have\n> conflicting files/uncommitted changes etc.\n>\n>> 2. git checkout origin/foo\n>> By this command, I am checking out files in remote branch origin/foo,\n>> but don't create a local branch, so I am not in any branch now. This is\n>> the reason why git tell me that I am in a 'detached HEAD'. Is this\n>> understanding right?\n>\n> Correct! Your working directory is updated, however it doesn't make\n> sense for you to make changes to a remote branch, so HEAD is updated\n> to be detached.\n>\n>>>\n>>> There are lots of patterns that can emerge from this functionality,\n>>> but the main thing to remember is that to create changes on top of a\n>>> remote branch, we first need to create a local copy of it. A 'detached\n>>> HEAD' here means that we are looking at the remote repository's branch\n>>> but don't have a local copy of it, so any changes we make might be\n>>> 'lost' (that is, not have an easy to find branch name).\n>>>\n>>\n>> I think here is a little confuse to me.  You mean that a 'detached HEAD'\n>> means I don't have a local copy, but I remember that if I run something\n>> like:\n>>     $ git checkout a-tag-name\n>> then I ususally went into 'detached HEAD' but my local files really get\n>> switched to those files in the tag 'a-tag-name'.  So what does you mean\n>> by 'don't have a local copy'?\n>\n> I should have been more clear. Here I mean that you don't have a local\n> copy of the branch reference. Your working directory is updated to be\n> in sync with the remote branch, but you haven't yet copied that remote\n> reference to a local branch that you can update with your changes.\n>\n> Hope that clears it up.\n>\n\nAndre, by this in further exaplaination, I think I fully understood.\nThanks a lot!\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205015","messageId":"slrnkctgqh.mmj.narkewoody@zuhnb712.local.com","threadId":"32365","inReplyTo":"1355722245-ner-6603@calvin","subject":"Re: How to specify remote branch correctly","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-17T07:02:46Z","receivedAt":"2012-12-17T07:02:46Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"On 2012-12-17, Tomas Carnecky <tomas.carnecky@gmail.com> wrote:\n> On Mon, 17 Dec 2012 16:13:08 +1100, Andrew Ardill\n> <andrew.ardill@gmail.com> wrote:\n>> On 17 December 2012 16:06, Woody Wu <narkewoody@gmail.com> wrote:\n>> > 1. git checkout foo.  By this command, I think I am checking out\n>> > files in my local branch named foo, and after that I also switch to\n>> > the branch. Right?\n>> \n>> Correct. Your working directory (files) switch over to whatever your\n>> local branch 'foo' points to, and your HEAD is updated to point to\n>> your local branch 'foo'. Unless something goes wrong/you have\n>> conflicting files/uncommitted changes etc.\n>\n> 'git checkout foo' has special meaning if a local branch with that\n> name doesn't exist but there is a remote branch with that name. In\n> that case it's equivalent to: git checkout -t -b foo origin/foo.\n> Because that's what people usually want.\n\nI think this is what exactly happened to me in the first time I got the\n'foo'.  One new thing to me is the '-t'.  I am not sure wether the '-t'\nwas used or not in the background.  How do I check the 'upstream'\nrelationships?  Is there any file under .git recoreded that kind of\ninformation?\n\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"},{"id":"205022","messageId":"1355728904-ner-4851@calvin","threadId":"32365","inReplyTo":"slrnkctgqh.mmj.narkewoody@zuhnb712.local.com","subject":"Re: How to specify remote branch correctly","fromName":"Tomas Carnecky","fromEmail":"tomas.carnecky@gmail.com","sentAt":"2012-12-17T07:21:44Z","receivedAt":"2012-12-17T07:21:44Z","isPatch":false,"sender":{"key":"tomas.carnecky@gmail.com","avatar":null},"body":"On Mon, 17 Dec 2012 07:02:46 +0000, Woody Wu <narkewoody@gmail.com> wrote:\n> On 2012-12-17, Tomas Carnecky <tomas.carnecky@gmail.com> wrote:\n> > 'git checkout foo' has special meaning if a local branch with that\n> > name doesn't exist but there is a remote branch with that name. In\n> > that case it's equivalent to: git checkout -t -b foo origin/foo.\n> > Because that's what people usually want.\n> \n> I think this is what exactly happened to me in the first time I got the\n> 'foo'.  One new thing to me is the '-t'.  I am not sure wether the '-t'\n> was used or not in the background.  How do I check the 'upstream'\n> relationships?  Is there any file under .git recoreded that kind of\n> information?\n\nYes, that information is recorded in a file somewhere in .git. However, for\nmost users it's irrelevant which file it is. Git has commands to access this\ninformation. Try one of these:\n\n  git branch -vv\n  git remote show origin\n  git rev-parse --abbrev-ref --symbolic-full-name @{u}\n"},{"id":"205029","messageId":"slrnkctj37.mmj.narkewoody@zuhnb712.local.com","threadId":"32365","inReplyTo":"1355728904-ner-4851@calvin","subject":"Re: How to specify remote branch correctly","fromName":"Woody Wu","fromEmail":"narkewoody@gmail.com","sentAt":"2012-12-17T07:41:33Z","receivedAt":"2012-12-17T07:41:33Z","isPatch":false,"sender":{"key":"narkewoody@gmail.com","avatar":null},"body":"On 2012-12-17, Tomas Carnecky <tomas.carnecky@gmail.com> wrote:\n> On Mon, 17 Dec 2012 07:02:46 +0000, Woody Wu <narkewoody@gmail.com> wrote:\n>> On 2012-12-17, Tomas Carnecky <tomas.carnecky@gmail.com> wrote:\n>> > 'git checkout foo' has special meaning if a local branch with that\n>> > name doesn't exist but there is a remote branch with that name. In\n>> > that case it's equivalent to: git checkout -t -b foo origin/foo.\n>> > Because that's what people usually want.\n>> \n>> I think this is what exactly happened to me in the first time I got the\n>> 'foo'.  One new thing to me is the '-t'.  I am not sure wether the '-t'\n>> was used or not in the background.  How do I check the 'upstream'\n>> relationships?  Is there any file under .git recoreded that kind of\n>> information?\n>\n> Yes, that information is recorded in a file somewhere in .git. However, for\n> most users it's irrelevant which file it is. Git has commands to access this\n> information. Try one of these:\n>\n>   git branch -vv\n\nRun this on my local linux tree, I got:\n  lgf2410-2.6.16.4         7af1fda - added a ignore rule in .gitignore\n  (*~)\n  * lgf2410-2.6.34.13        50d3f9d ax88796b verbose debug output\n    lgf2410-2.6.34.13-16C554 3ec82e0 more debug on 16C554\n      master                   9489e9d [origin/master] Linux 3.7-rc7\n\nDoes this mean, I only have local branch master tracked to remote?\n\n\n>   git remote show origin\nRunning this I got,\n\n    ...\n    linux-3.1.y    tracked\n    linux-3.2.y    tracked\n    linux-3.3.y    tracked\n    linux-3.4.y    tracked\n    linux-3.5.y    tracked\n    linux-3.6.y    tracked\n    linux-3.7.y    new (next fetch will store in remotes/origin)\n    master         tracked\n  Local branch configured for 'git pull':\n    master rebases onto remote master\n  Local ref configured for 'git push':\n    master pushes to master (local out of date)\n\nI am curious to know how the last 4 lines were printed by git.\n\n  -----\n  Local branch configured for 'git pull':\n    master rebases onto remote master\n  -----\n\nIf I have addtional branch other than master that also track to some\nremote branch, will it also be listed under this 'git pull' line?\n\n  ----\n  Local ref configured for 'git push':\n    master pushes to master (local out of date)\n  ---\n\nThis I totally don't understand, what it mean? I think I did not do a\nmodification on the local 'master'.\n\nThanks!\n\n-- \nwoody\nI can't go back to yesterday - because I was a different person then.\n"}]}