Take the 2-minute tour ×

While I was working on a feature_branch I ended up fixing a bug for the whole site. I want to commit the bug fix to master, not my feature_branch. The fix involved adding some new files so when I try to checkout master it aborts and warns me that the untracked files would be overwritten.

How can I switch to master and bring untracked files with me?

share|improve this question
This warning sounds like you already have some files in master with same names as your untracked files. –  Paŭlo Ebermann Feb 19 '11 at 21:43
add comment

3 Answers

up vote 9 down vote accepted

Something's not right. Normally when you switch branches the untracked files are brought along with you without any notice. That's why they're called "untracked". However, you say that the untracked files would be overwritten. This implies that you have created an untracked file in the new branch which already exists in the master branch. This means that you have to decide what you want to do: which one to keep. This isn't a matter of getting git to do something, it's a matter of you not being clear in what you want it to do.

Assuming you want to somehow resolve the conflict between the two copies of the same file, you can do

git checkout feature_branch
git stash
git checkout master
git stash pop

And then resolve the conflicts that will arise.

share|improve this answer
add comment

One approach to this problem is to stash your changes, then restore them on master.

  1. Make sure you've committed everything else that's unrelated to this bug fix
  2. Run git stash save "bug fix for master"
  3. git checkout master
  4. git stash pop
  5. Resolve any conflicts resulting from the stash pop
  6. Commit this fix to master
  7. Switch back to your feature branch
share|improve this answer
add comment

Easiest solution i can think of is make a local copy of your untracked/modified files. Then checkout your master and reupload and add commit from there. If there are any conflicts, git will notify you and you can merge at that point.

share|improve this answer
add comment

Your Answer


