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

git-checkout question

From
DNDavid J. Neu <davidjneu@gmail.com>
Date
Jan 13, 2008, 14:21 UTC
Message-ID
<20080113142140.GB10426@bach.davidneu.local>
Hi, 
I was wondering if someone could explain the following behavior.
1. create and switch to branch off master
2. edit a file in the branch
3. checkout master without committing changes in the branch
4. the changes in the branch are automatically applied in working tree 
   in master

I wasn't expecting the changes in the branch to be automatically moved to master. Had I committed while in the branch this doesn't happen. I'm using git version 1.5.3, the details are below.

Many thanks!

Cheers, David

[/tmp] mkdir git-test
[/tmp] cd git-test
[/tmp/git-test] git-init 
Initialized empty Git repository in .git/
[/tmp/git-test] # create hello.py
[/tmp/git-test] git-add hello.py 
[/tmp/git-test] git-commit   
Created initial commit 58282ee: Initial commit of git-test.
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 hello.py
[/tmp/git-test] cat hello.py 
print "hello from master."
[/tmp/git-test] git-checkout -b test-branch
Switched to a new branch "test-branch"
[/tmp/git-test] # modify hello.py
[/tmp/git-test] cat hello.py 
print "hello from test-branch."
[/tmp/git-test] git-checkout master
M       hello.py
Switched to branch "master"
[/tmp/git-test] cat hello.py 
print "hello from test-branch."
[/tmp/git-test] # hmmm?
Next: Steffen Prohaska
Message 1 of 3 in “git-checkout question”
  1. David J. NeuJan 13, 2008
  2. Steffen ProhaskaJan 13, 2008
  3. David J. NeuJan 13, 2008

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.