This article will illustrate:
- Difference Between Stash and Stage Files in Git
- How to Stash Files in Git?
- How to Stage Files in Git?
Difference Between Stash and Stage Files in Git
In Git, the “Stash” is a process that saves the untracked modified files into the stack. Stash changes are unnecessary changes that need not be added to the Git index. On the other hand, the “Stage” is the step that adds the untracked files to the Git staging area for tracking purposes.
How to Stash Files in Git?
To stash files in Git, first, switch to the required directory and view its current status. Then, write out the “git stash” command to save the untracked or uncommitted changes to the stash and verify changes.
Step 1: View Current Status
First, type out the below-provided command to check the current status of the working directory:
It can be seen that the current repository contains “Test1.txt” and “Test2.txt” two modified files that need to be tracked:
Step 2: Stash Files
Then, save the untracked files changes to the stash using the provided command:
Step 3: View Stash History
Next, enter the following command to view the stored changes in the stash:
According to the below output, the files changes have been stored in the stash:
Step 4: Verify Changes
Lastly, check the current status of the working repository:
As you can see the Git status is clear now which indicates that the changes have been stashed successfully:
How to Stage Files in Git?
To stage all files in Git, utilize the “git add .” command. Moreover, if the user wants to add a single file, the “git add <file-name>” command can be used.
Step 1: View Repository Status
First, check the current status of the working directory:
It can be observed that the repository contains two untracked or unstaged files:
Step 2: Stage Files
Now, run the provided command to add files to the Git staging area for tracking purposes:
Step 3: Verify Changes
To verify whether the files have been staged or not, check the Git status:
It can be observed that the unstaged files’ changes have been staged successfully:
We have explained about the stash and stage files in Git.
Conclusion
“Stash” saves the untracked modified files’ changes into the stash list. To stash changes, the “git stash” command is utilized. On the other hand, “Stage” moves the untracked changes to the Git index. To all files to the Git index, utilize the “git add .” command. This article illustrated the difference between stash and stage files in Git.