Stashing Untracked Or Ignored Files
We can use the git stash command to stash the files which are untracked or ignored files. By following the below steps we can stash our files:
Step 1: Stash the changes for that using the below command.
git stash save --include-untracked
–include-untracked by this it will stash all the untracked files also.
Step 2: Verify the stash:
Use the below command to confirm that the stash was created:
git stash list
Step 3: By using the following command we can bring back back and apply the stash.
git stash apply stash@{0}
Step 4: Once completion of bringing the stash back if it is unwanted we can delete the stash by using the following command.
git stash drop stash@{0}
Git | Working with Stash
Pre-requisites: Git
Git allows multiple users to work on the same project simultaneously. Suppose a developer is working on a feature in a branch and he needs to pull changes from some other developer’s branch or if he has to work urgently on some other feature, but the feature he is currently working on is incomplete. In this case, you cannot commit the partial code of the currently working feature. To add this new feature, you have to remove your current changes and store them somewhere else. For this type of situation, Git offers a very useful command known as ‘git stash‘. git stash command saves the previously written code and then returns to the last commit for a fresh start. Now you can add the new feature without disturbing the old one as it is saved locally. After committing to the new feature you can go on with working on the old feature which was incomplete and uncommitted.