Why does 'git checkout' work only for some branches?

Here is the result of two checkouts: why the second is failing? ‘git status’ shows some files have been modified, but I am sure I haven’t touched those files.

praveensripati@MyMini:~/Hadoop/Git/hadoop-common$ git checkout branch-0.21  
Switched to branch 'branch-0.21'  

praveensripati@MyMini:~/Hadoop/Git/hadoop-common$ git checkout branch-0.20  
error: The following untracked working tree files would be overwritten by checkout:  
Please move or remove them before you can switch branches.  

praveensripati@MyMini:~/Hadoop/Git/hadoop-common$ git status
# On branch trunk
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#   CHANGES.txt
#   LICENSE.txt
#   README.txt
#   bin/
#   build.xml
#   conf/
#   lib/
#   site/
#   src/
nothing added to commit but untracked files present (use "git add" to track)

  • undo git pull of wrong branch onto master
  • What does “fatal: You are on a branch yet to be born” mean in this context
  • SVN Error E175002
  • GIT: commit changes to old/safe branch while in new/dirty/dev branch without checking out or losing unstaged data
  • Git checkout repository from N days ago
  • Get git current branch/tag name
  • How to push to a new branch in Git carefully
  • 'X' does not appear to be a git repository (I'm sure the path is correct)
  • git ls-files sort by modification time
  • How can I get a list of git branches, ordered by most recent commit?
  • Gitiginore all files except those with .rst extensions?
  • How do I properly force a Git push?
  • 3 Solutions collect form web for “Why does 'git checkout' work only for some branches?”

    This is occurring because some or all of the files that are not being tracked on your current branch are being tracked by the branch you want to change to.

    For example the branch may contain a CHANGES.txt. Because git does not want to overwrite the file you have in your workspace if is giving your this error to allow you to backup the files you have locally. You can either:

    1. Move these files somewhere safe
    2. If you are sure you don’t need these files, you can perform a checkout -f to switch to the branch (this will overwrite any files that conflict)

    Stashing does not work for files that are not tracked on the current branch. You can use git diff to work out which files are on the 0.20 but not on 0.21. For example:

    git diff --name-only branch-0.20

    That can happen if there is a filter in place, automatically changing the content of those files on checkout. As in:


    (See Why should I use core.autocrlf=true in Git?)

    For instance, if the eol style is changed automatically, you would have modified files in your working tree.
    And that would be enough to prevent another checkout with common modified files.

    You can stash the changes, as Kit suggests, but I would recommend understanding first why those changes happen in the first place.

    git stash 
    git checkout branch-0.20
    git stash apply

    try above

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