13

I have two branches one is called master the other is called dev I am currently in the master branch and I want to go to the dev branch to move a file to the development server. however when I perform a

$ git checkout dev

I get the message:

The following untracked working tree files would be overwritten by checkout:

pages/memclub/images/subheaders/leadership.png
pages/memclub/images/subheaders/male.png
pages/memclub/images/subheaders/marketing.png
pages/memclub/images/subheaders/training.png

I dont want to commit the files to the master, they are not ready to be pushed.

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Matthew Colley
  • 10,816
  • 9
  • 43
  • 63

1 Answers1

28

First you'll want to add the files in question so that they're tracked by Git (you don't have to commit any changes, but Git needs to know about the files):

git add pages/memclub/images/subheaders/leadership.png pages/memclub/images/subheaders/male.png 
git add pages/memclub/images/subheaders/marketing.png pages/memclub/images/subheaders/training.png

Then you can stash your changes:

git stash 

When you're ready to start working on the files again, you can use:

git stash pop
Ethan Brown
  • 26,892
  • 4
  • 80
  • 92
  • when trying the git stash - get the error: No local changes to save – Matthew Colley Sep 07 '12 at 18:17
  • 1
    Oh, right, because your files are untracked. You'll have to `git add` them first, then stash. You don't have to commit them, but you do have to add them. – Ethan Brown Sep 07 '12 at 18:22
  • Insead of `git stash pop` you can also use `git stash apply`. Pop will pop out your files from stash but apply will copy files from stash – Abhishek Gupta Sep 07 '12 at 18:50
  • 1
    knoxxs, `git stash pop` and `git stash apply` are synonyms; they don't do anything differently. – Ethan Brown Sep 07 '12 at 18:58
  • 5
    @EthanBrown that's not true, @knoxxs is right. From the documentation: `Like pop, but do not remove the state from the stash list. Unlike pop, may be any commit that looks like a commit created by stash save or stash create.` – pedromanoel Mar 27 '13 at 20:38
  • 1
    Instead of adding the files, you can also use `git stash --include-untracked` (or `-u` for short). – Lutz Prechelt Aug 29 '22 at 09:07