Why do files in the working directory get the modified status on switching between Git branches?

I have two branches in my local git repository: master and anotherbranch. When I switch from master to anotherbranch with git checkout anotherbranch and run git status I see modified files.

I undo these modifications with git reset HEAD and then git status does not display them. However when I switch to master and switch to the branch afterwards I see these modified files again.

  • How to make existing branch an orphan in git
  • creating git branch after the fact?
  • Switching remote to a specific branch
  • Workflow to “backport” change into different Mercurial (Hg) branch?
  • Git: Teamwork across branches without Push Permission
  • git-svn isn't committing to branches, only trunk
  • Could you please explain what is going on?

  • Does `git reset HEAD file` also check out the file?
  • OpenSSL errno 10054,connection refused, whilst trying to connect to our server
  • Git push results in “Authentication Failed”
  • Git push to azure websites with submodule
  • How can I know in git if a branch has been already merged into master?
  • Git mergetool vs difftool
  • 3 Solutions collect form web for “Why do files in the working directory get the modified status on switching between Git branches?”

    You wouldn’t have autocrlf set to true, by any chance?
    Because it can change your files on a checkout…

    See the thread “core.autocrlf considered half-assed”:

    Back then, I was not a fan of the core.autocrlf support.
    *But I have to admit that in the meantime, I turned into an outright un-fan of the feature. Not because its intent is wrong, but because its implementation is lousy.

    Just try to git reset --hard or git stash when there are files with DOS line endings and when core.autocrlf is not false.

    And then despair.

    If the items are not tracked in either branch, the files will show up in git status as untracked, and will survive across checkouts

    The git reset –hard will remove the modification from the index. Try with this additional argument it should be OK after that.

    Git Baby is a git and github fan, let's start git clone.