Monday, September 18, 2023

git stash usages

----
Sure, here are some examples of how you gcan use `git stash`:

1. **Save changes to a new stash**:
   
   - Suppose you're working on a new feature in a dedicated branch, but you need to switch to another branch to fix a bug.
   - You've made changes that you don't want to commit yet, so you can stash them. Here's how you can do it:

   ```bash
   git stash save "WIP on new feature"
   ```

   This command will save your changes to a new stash with the message "WIP on new feature". You can use any message that helps you remember what changes are in the stash.

2. **List all stashes**:
   - If you want to see all of the stashes that you've currently saved, you can use this command:

   ```bash
   git stash list
   ```

   This command will show you a list of all stashes that you currently have.

3. **Apply changes from the most recent stash**:
  - Once you're ready to continue working on your new feature, you can apply the changes from your most recent stash using this command:

   ```bash
   git stash pop
   ```

   This command will apply the changes from the most recent stash and then remove it from your list of stashes.

4. **Apply changes from a specific stash**:
  -  If you have multiple stashes and you want to apply changes from a specific one, you can do so with this command:

   ```bash
   git stash apply stash@{10}
   ```

   This command will apply the changes from the stash named `stash@{10}`.

5. **Discard the most recent stash**:
   - If you decide that you no longer need the changes in your most recent stash, you can discard it with this command:

   ```bash
   git stash drop
   ```

   This command will discard the most recent stash.

6. **Remove all stashes**:
   - If you want to remove all of your stashes at once, you can use this command:

   ```bash
   git stash clear
   ```

   This command will remove all of your stashes.

Note Remember, any changes that are stashed are kept locally and are not transferred when you push your commits to a remote repository.

No comments:

Post a Comment