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

Re: What is the mechanism of a git checkout?

From
Jakub Narebski <jnareb@gmail.com>
Date
May 29, 2009, 09:05 UTC
Message-ID
<m3hbz4b7ov.fsf@localhost.localdomain>
In-Reply-To
<slrnh1udov.6ls.sitaramc@sitaramc.homelinux.net>
Sitaram Chamarty <sitaramc@gmail.com> writes:
Show 16 quoted lines
> On 2009-05-28 15:21:59, mastermindxs <mastermindxs@gmail.com> wrote:
> >
> > does a git checkout pull the contents of a branch? how does it
> > physically separate files in your working directory from other
> > branches?
> >
> > The speed of which it works leads me to the logical conclusion
> > that the files in the working directory are all there for all
> > branches and git simply only shows you the files of the active
> > branch.
> >
> > Can anyone shed more light on the underlying mechanisms of git
> > checkout maybe even branch and merge as well?
> 
> I explain it as below when I get asked this question.  It's
> a simplified answer but largely correct, I believe.
[...]
Show 12 quoted lines
>   - files that do show up in "git status" in the "before"
>     branch, are either modified or staged.
>     
>     - if the "before" branch version is the same as the
>       "after" branch version, that also is not touched.  In
>       the new branch, running "git status" will show you the
>       same files.
> 
>     - if the "before" branch version and the "after" branch
>       version are *not* the same, git would lose your local
>       (uncommitted) changes, so it refuses to do the
>       checkout and stays where it is.

In which case (there is file which is different in "before" and "after", and which is modified in working area) you can ask git to try to 'move' (merge) changes from "before" to "after" version of a file with '-m' / --merge option, see git-checkout(1):

  git checkout -m after
-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Sitaram Chamarty
Message 4 of 4 in “What is the mechanism of a git checkout?”
  1. mastermindxsMay 28, 2009
  2. Peter HarrisMay 28, 2009
  3. Sitaram ChamartyMay 29, 2009
  4. Jakub NarebskiMay 29, 2009

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.