๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก is a Git command that allows developers to save changes in their working directory without committing them. This is particularly useful when you are in the middle of working on a feature or a bug fix, and you need to switch to another branch, pull changes from a remote repository, or perform other operations that require a clean working directory.
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก is a powerful command in a developerโs arsenal, especially in dynamic development environments where tasks can change rapidly. It facilitates a smooth workflow by allowing developers to manage and switch between different tasks without the need for unnecessary commits. When used judiciously, git stash contributes to a more organized and efficient version control process in DevOps workflows.
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 ๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก. ๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก 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.
๐ ๐๐๐ฒ ๐๐ฌ๐ ๐๐๐ฌ๐๐ฌ:
โข ๐๐๐ฆ๐ฉ๐จ๐ซ๐๐ซ๐ฒ ๐๐ญ๐จ๐ซ๐๐ ๐:
Developers can stash changes that are not ready to be committed but need to be set aside temporarily. This is common when interrupted by urgent tasks or when transitioning between different tasks.
โข ๐๐ซ๐๐ง๐๐ก ๐๐ฐ๐ข๐ญ๐๐ก๐ข๐ง๐ :
Before switching branches, developers can stash changes to avoid conflicts. This is helpful when working on multiple features simultaneously or when switching to a branch with ongoing development.
โข ๐๐ฎ๐ฅ๐ฅ๐ข๐ง๐ ๐๐ก๐๐ง๐ ๐๐ฌ:
Before pulling changes from a remote repository, itโs a good practice to stash local changes to prevent conflicts. After pulling changes, developers can apply the stash to reapply their work.
โข ๐๐จ๐ง๐๐ฅ๐ข๐๐ญ ๐๐๐ฌ๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง:
During a merge or rebase operation, conflicts may arise. Stashing changes allows developers to resolve conflicts more easily and cleanly.
โข ๐๐ซ๐๐๐ญ๐ข๐ง๐ ๐๐ฅ๐๐๐ง ๐๐จ๐ฆ๐ฆ๐ข๐ญ๐ฌ:
Stashing can be used to create clean, logically separated commits. Developers can stash changes, commit the current state, and then apply the stash to continue working.
Benefits of Mastering Git Stash (Why You Should Care):
โข Enhanced Workflow Efficiency: Seamlessly switch branches or pull updates without worrying about losing your progress. Git Stash ensures a smooth development flow, allowing you to context-switch between tasks effortlessly.
โข Clearer Commit History: By keeping unfinished work out of your commits, you maintain a clean and concise commit history. This makes it easier for you and your teammates to understand the evolution of the codebase.
โข Collaboration Made Easy: Working on a project with a team? Git Stash empowers effective collaboration. You can freely switch to different branches to address bugs or contribute to features without affecting your teammatesโ work.
๐ ๐๐๐ฌ๐ญ ๐๐ซ๐๐๐ญ๐ข๐๐๐ฌ
โข Always stash changes in a clean working directory to avoid conflicts during the stash application.
โข Provide meaningful stash messages for clarity when reviewing stashes later.
โข Regularly check and manage your stashes to avoid unnecessary clutter.
๐๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐จ๐ฆ๐ฆ๐๐ง๐๐ฌ
โข ๐๐ญ๐๐ฌ๐ก ๐๐ก๐๐ง๐ ๐๐ฌ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก
Stashes both staged and unstaged changes.
โข ๐๐ญ๐๐ฌ๐ก ๐ฐ๐ข๐ญ๐ก ๐ ๐๐๐ฌ๐ฌ๐๐ ๐
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฌ๐๐ฏ๐ โ๐๐จ๐ฎ๐ซ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฆ๐๐ฌ๐ฌ๐๐ ๐โ
Stashes changes with a descriptive message.
โข ๐๐ญ๐๐ฌ๐ก ๐๐ง๐ญ๐ซ๐๐๐ค๐๐ ๐
๐ข๐ฅ๐๐ฌ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก -๐ฎ ๐จ๐ซ ๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก โ ๐ข๐ง๐๐ฅ๐ฎ๐๐-๐ฎ๐ง๐ญ๐ซ๐๐๐ค๐๐
Stashes untracked files along with changes.
โข ๐๐ข๐ฌ๐ญ ๐๐ญ๐๐ฌ๐ก๐๐ฌ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฅ๐ข๐ฌ๐ญ
Lists all stashes youโve created.
โข ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐๐ญ๐๐ฌ๐ญ ๐๐ญ๐๐ฌ๐ก
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ฉ๐ฉ๐ฅ๐ฒ
Applies the latest stash to the working directory. The stash is not removed.
โข ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐ ๐๐ฉ๐๐๐ข๐๐ข๐ ๐๐ญ๐๐ฌ๐ก
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐ฌ๐ญ๐๐ฌ๐ก@{๐ง}
Applies the stash with index ๐ง.
โข ๐๐จ๐ฉ ๐๐๐ญ๐๐ฌ๐ญ ๐๐ญ๐๐ฌ๐ก (๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐ง๐ ๐๐ซ๐จ๐ฉ)
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฉ๐จ๐ฉ
Applies the latest stash and removes it from the stash list.
โข ๐๐ซ๐จ๐ฉ ๐ ๐๐ญ๐๐ฌ๐ก
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ซ๐จ๐ฉ
Removes the latest stash without applying it.
โข ๐๐ซ๐จ๐ฉ ๐ ๐๐ฉ๐๐๐ข๐๐ข๐ ๐๐ญ๐๐ฌ๐ก
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ซ๐จ๐ฉ ๐ฌ๐ญ๐๐ฌ๐ก@{๐ง}
Removes the stash with index ๐ง.
โข ๐๐ฅ๐๐๐ซ ๐๐ฅ๐ฅ ๐๐ญ๐๐ฌ๐ก๐๐ฌ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ฅ๐๐๐ซ
Removes all stashes.
โข ๐๐ซ๐๐๐ญ๐ ๐ ๐๐๐ฐ ๐๐ซ๐๐ง๐๐ก ๐๐ง๐ ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐ญ๐๐ฌ๐ก
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ซ๐๐ง๐๐ก <๐ง๐๐ฐ_๐๐ซ๐๐ง๐๐ก_๐ง๐๐ฆ๐>
Creates a new branch and applies the latest stash to it.
โข ๐๐ก๐จ๐ฐ ๐๐ก๐๐ง๐ ๐๐ฌ ๐ข๐ง ๐ ๐๐ญ๐๐ฌ๐ก
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฌ๐ก๐จ๐ฐ -๐ฉ ๐ฌ๐ญ๐๐ฌ๐ก@{๐ง}
Shows the changes in a specific stash.
โข ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐ญ๐๐ฌ๐ก ๐ฐ๐ข๐ญ๐ก ๐๐ฎ๐ญ๐จ-๐๐๐ซ๐ ๐
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ฉ๐ฉ๐ฅ๐ฒ โ 3๐ฐ๐๐ฒ ๐ฌ๐ญ๐๐ฌ๐ก@{๐ง}
Attempts to apply the stash using a 3-way merge.
โข ๐๐ญ๐๐ฌ๐ก ๐๐ง๐ฅ๐ฒ ๐๐ง๐ญ๐ซ๐๐๐ค๐๐ ๐
๐ข๐ฅ๐๐ฌ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฌ๐๐ฏ๐ โ ๐ข๐ง๐๐ฅ๐ฎ๐๐-๐ฎ๐ง๐ญ๐ซ๐๐๐ค๐๐
Stashes only untracked files.
โข ๐๐ญ๐๐ฌ๐ก ๐๐๐๐ฉ๐ข๐ง๐ ๐๐ง๐๐๐ฑ ๐๐ก๐๐ง๐ ๐๐ฌ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฌ๐๐ฏ๐ โ ๐ค๐๐๐ฉ-๐ข๐ง๐๐๐ฑ
Stashes changes but keeps changes in the index.
โข ๐๐ญ๐๐ฌ๐ก ๐๐ก๐๐ง๐ ๐๐ฌ ๐ข๐ง๐ญ๐๐ซ๐๐๐ญ๐ข๐ฏ๐๐ฅ๐ฒ
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐ฌ๐๐ฏ๐ -๐ฉ
Allows you to interactively choose which changes to stash.
โข ๐๐ฉ๐ฉ๐ฅ๐ฒ ๐๐ญ๐๐ฌ๐ก ๐๐ฌ ๐ ๐๐๐ซ๐ ๐
๐ ๐ข๐ญ ๐ฌ๐ญ๐๐ฌ๐ก ๐๐ฉ๐ฉ๐ฅ๐ฒ -๐ฆ <๐ฆ๐๐ซ๐ ๐_๐ฉ๐๐ซ๐๐ง๐ญ_๐ง๐ฎ๐ฆ๐๐๐ซ>
Applies the stash as a merge. Useful when the stash represents changes from a different branch.