git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Woody Wu <narkewoody@gmail.com>
To: git@vger.kernel.org
Subject: Re: How to specify remote branch correctly
Date: Mon, 17 Dec 2012 06:48:57 +0000 (UTC)	[thread overview]
Message-ID: <slrnkctg0k.mmj.narkewoody@zuhnb712.local.com> (raw)
In-Reply-To: CAH5451kmTW+nO4V4pjSdaqhHAb=RX-tawLo=rJfuPnDRDWeSEA@mail.gmail.com

On 2012-12-17, Andrew Ardill <andrew.ardill@gmail.com> wrote:
> On 17 December 2012 16:06, Woody Wu <narkewoody@gmail.com> wrote:
>> 1. git checkout foo.
>> By this command, I think I am checking out files in my local branch
>> named foo, and after that I also switch to the branch. Right?
>
> Correct. Your working directory (files) switch over to whatever your
> local branch 'foo' points to, and your HEAD is updated to point to
> your local branch 'foo'. Unless something goes wrong/you have
> conflicting files/uncommitted changes etc.
>
>> 2. git checkout origin/foo
>> By this command, I am checking out files in remote branch origin/foo,
>> but don't create a local branch, so I am not in any branch now. This is
>> the reason why git tell me that I am in a 'detached HEAD'. Is this
>> understanding right?
>
> Correct! Your working directory is updated, however it doesn't make
> sense for you to make changes to a remote branch, so HEAD is updated
> to be detached.
>
>>>
>>> There are lots of patterns that can emerge from this functionality,
>>> but the main thing to remember is that to create changes on top of a
>>> remote branch, we first need to create a local copy of it. A 'detached
>>> HEAD' here means that we are looking at the remote repository's branch
>>> but don't have a local copy of it, so any changes we make might be
>>> 'lost' (that is, not have an easy to find branch name).
>>>
>>
>> I think here is a little confuse to me.  You mean that a 'detached HEAD'
>> means I don't have a local copy, but I remember that if I run something
>> like:
>>     $ git checkout a-tag-name
>> then I ususally went into 'detached HEAD' but my local files really get
>> switched to those files in the tag 'a-tag-name'.  So what does you mean
>> by 'don't have a local copy'?
>
> I should have been more clear. Here I mean that you don't have a local
> copy of the branch reference. Your working directory is updated to be
> in sync with the remote branch, but you haven't yet copied that remote
> reference to a local branch that you can update with your changes.
>
> Hope that clears it up.
>

Andre, by this in further exaplaination, I think I fully understood.
Thanks a lot!

-- 
woody
I can't go back to yesterday - because I was a different person then.

      parent reply	other threads:[~2012-12-17  6:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-17  2:30 How to specify remote branch correctly Woody Wu
2012-12-17  4:27 ` Andrew Ardill
2012-12-17  5:06   ` Woody Wu
2012-12-17  5:13     ` Andrew Ardill
2012-12-17  5:30       ` Tomas Carnecky
2012-12-17  5:52         ` Andrew Ardill
2012-12-17  6:44           ` Chris Rorvick
2012-12-17  7:02         ` Woody Wu
2012-12-17  7:21           ` Tomas Carnecky
2012-12-17  7:41             ` Woody Wu
2012-12-17  6:48       ` Woody Wu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrnkctg0k.mmj.narkewoody@zuhnb712.local.com \
    --to=narkewoody@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).