Search code examples
gitgithubbranchgit-checkoutworking-directory

Git branch switch not changing working directory


When I run the command:

$ git checkout 'newBranch'

I get the following:

M   path/to/file1.js
M   path/to/file2.js
D   path/to/file3.js
M   path/to/file4.js
Switched to branch 'newBranch'

And my working directory remains the same as it was with the original branch.

Up until this point whenever I've run git checkout <branch-name>, it has switched my working directory to whatever was in the other local branch - which is what I would expect/hope to occur.

I don't know why this has changed.

Is there anything that might be causing this?


Solution

  • I have just figured out what I did wrong, in case anyone else has this problem: I forgot to add and commit my changes in the previous branch, so it carried those uncommitted changed into my secondary branch, and maintained the working directory.

    To avoid this, ensure all changes are added and committed before switching branches.