Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+6 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. But git stash by itself stashes only the changes to the existing file; the new file remains in my working tree, cluttering up my future work. How do I stash this untracked file?

2 Answers

+6 votes
by (50.2k points)

For this query, there is an update in git so for

New versions of git now have 

git stash --all 

which stashes all files, including untracked and ignored files.

git stash --include-untracked 

no longer touches ignored files.

As of version 1.7.7, you can use

git stash --include-untracked 

or 

git stash save -u 

to stash untracked files without staging them.

Add (git add) the file and start tracking it. Then stash. But with the update, this is no longer exists.

Reference: https://git-scm.com/docs/git-stash

+8 votes
by (62.9k points)

I used

git stash 

for stashing the modified .gitIgnore file.

For stashing .classpath and .project file, I used

git stash --include-untracked

and it removed the files from my local repository. Absence of these files takes away my capability of working on my work location in eclipse. So, I proceeded on with completing the procedure for pushing the committed files to a remote location. Once I have pushed the committed files successfully, I used

git stash pop

This pasted the same files back in my workspace. This gave back to me my ability to work on the same project in eclipse. Hope this helps you!

Related questions

+9 votes
2 answers
0 votes
1 answer
asked Aug 2, 2019 in DevOps and Agile by Han Zhyang (19.7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...