Git stash

by

git stash command in Git is used to temporarily save changes that you have made in your working directory but are not ready to commit. It allows you to store your modifications in a “stash” and revert your working directory back to a clean state, so you can switch branches, pull changes from remote repositories, or perform other operations without committing the changes. Later, you can apply the stash and continue working on your changes. Here’s how you can use git stash:

  1. Stashing Changes:
    • Run git stash save to create a new stash. You can also include a message to describe the changes you’re stashing, like git stash save "Work in progress".
    • Git will stash your changes and revert your working directory to a clean state, removing the modifications.
  2. Switching Branches:
    • Once your changes are stashed, you can switch to a different branch using git checkout or perform any other Git operation without interference from your uncommitted changes.
  3. Applying the Stashed Changes:
    • To apply your stashed changes, use git stash apply or git stash pop.
      • git stash apply reapplies the changes from the most recent stash without removing it from the stash list.
      • git stash pop reapplies the changes from the most recent stash and removes it from the stash list.
    • You can also specify a specific stash to apply by using git stash apply stash@{n}, where n is the index of the stash in the stash list.
  4. Delete Stashes:
    • If you no longer need a stash, you can delete it from the stash list using git stash drop stash@{n}.
    • To remove all stashes, you can use git stash clear.
  5. View Stashes:
    • To view the list of stashes and their details, you can use git stash list. It shows the stash index, description, and branch where the stash was created.

Leave a Reply

Your email address will not be published. Required fields are marked *