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

Re: question concerning branches

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 19, 2009, 18:35 UTC
Message-ID
<7vr5v7vehj.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4a8c373f@wupperonline.de>
ib@wupperonline.de (Ingo Brueckl) writes:
Show 11 quoted lines
> I'm a git novice and have a comprehension question concerning branches.
>
> Within a git repository, I do:
>
>   git branch test
>   git checkout test
>   # edit foo.bar
>   git checkout master
>
> I'd expect that master is in the exactly same unchanged state it was at
> branching time, but what a surprise, foo.bar is modified here, too!

No. Local modification that are not committed do not belong to any branch. Rather it belongs to your work tree and the index, and follow you when you switch branches.

This is one of the most useful features. For example, it is an essential part of supporting the workflow described here:

    http://gitster.livejournal.com/25892.html

On the other hand, there are cases that you do not want to see your local changes to foo.bar appear when you switch back to master, and the most obvious case is "I started working on something, and I used a separate branch 'test' because the change will be involved. I am in the middle of the work, the changes so far I made to foo.bar is far from ready, but I have to handle emergency fix on the master branch". For that kind of situation, you can use "git stash", like:

    http://gitster.livejournal.com/29577.html
Previous: Jakub NarebskiNext: Ingo Brueckl
Message 19 of 21 in “question concerning branches”
  1. Ingo BruecklAug 19, 2009
  2. Bruce StephensAug 19, 2009
  3. Avery PennarunAug 19, 2009
  4. Ingo BruecklAug 19, 2009
  5. Jakub NarebskiAug 19, 2009
  6. Ingo BruecklAug 19, 2009
  7. Avery PennarunAug 19, 2009
  8. Matthieu MoyAug 20, 2009
  9. Jacob HelwigAug 19, 2009
  10. Jakub NarebskiAug 19, 2009
  11. Theodore TsoAug 19, 2009
  12. Jakub NarebskiAug 19, 2009
  13. Theodore TsoAug 20, 2009
  14. Linus TorvaldsAug 19, 2009
  15. Randal L. SchwartzAug 20, 2009
  16. Ingo BruecklAug 20, 2009
  17. Johannes SixtAug 20, 2009
  18. Jakub NarebskiAug 20, 2009
  19. Junio C HamanoAug 19, 2009
  20. Ingo BruecklAug 19, 2009
  21. Andreas EricssonAug 20, 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.