🐙
Git Developer Guide
About
  • Overview
  • Scope of this book
  • Table of Content
  • 🐢Introduction to Version Control
    • What is Version Control?
    • Overview of git and it's benefits
    • Setting up Git on Different Platforms
  • 🍼Git Fundamentals
    • Initialising a new Git repository
    • Understanding the Git Workflow
    • Committing Changes and Writing Good Commit Messages
    • Viewing and Navigating Commit History
    • Git Basics - Practice Scenarios
      • Initialising a Git Repository
      • Committing Changes
      • Exploring Commit History
      • Amending and Undoing Commits
  • 🦕Working With Git
    • What is Git Branch?
    • Creating and Switching Between Branches
    • Merging Branches and Resolving Conflicts
    • Best Practices for Branch Management
    • Git Workflows
    • Git Log
    • Git Stash
    • Working with Git - Practice Scenarios
      • Creating and Switching Between Branches
      • Merging Branches and Resolving Conflicts
      • Branching Strategies in a Team Project
      • Rolling Back to a Previous Version
      • Experimenting with Feature Branches
      • Working with Stash
  • 🤝Working with Remote Repositories
    • Cloning a Repository from Remote
    • Pushing and Pulling Changes to and from Remote Repositories
    • Collaborative Workflows - Forking, Branching, and Pull Requests
    • Resolving Conflicts in a Collaborative Environment
    • Collaborating with Git - Practice Scenarios
      • Cloning a Remote Repository
      • Pushing and Pulling Changes
      • Collaborative Workflow with Forking and Pull Requests
      • Resolving Conflicts in a Pull Request
  • 🏆Advanced Git Features
    • Aliases and Custom Configurations
    • Working with Tags and Releases
    • Rewriting Commit History with Interactive Rebase
    • Utilising Git Hooks for Automation
    • Advanced Git Features - Practice Scenarios
      • Creating Custom Git Aliases
      • Working with Tags and Releases
      • Rewriting Commit History with Interactive Rebase
      • Using Git Hooks for Automated Testing
  • 😎Git in Real-World
    • Managing a Project with Multiple Contributors
    • Integrating Git with Continuous Integration, Continuous Deployment (CI, CD)
    • Versioning Assets with Git LFS (Large File Storage)
    • Deploying a Web Application using Git
    • Git In Real World - Practice Scenarios
      • Managing a Project with Multiple Contributors
      • Integrating Git with CICD Pipelines
      • Versioning Assets with Git LFS
      • Deploying a Web Application using Git
  • Git Troubleshooting
    • Common Mistakes and Pitfalls When Using Git
    • Undoing Changes with Git - Reverting and Resetting
    • Recovering Lost Commits or Branches
    • Dealing with Repository Corruption or Other Issues
  • Git Best Practices and Tips
    • Creating efficient git workflows: writing clean code for faster reviews
    • The importance of clean code in collaborative development
    • Significance of consistent naming conventions & coding Standards
    • Good code documentation for better git workflows
    • Writing meaningful git commit messages
    • Atomic commits in git & it's benefits for software teams
    • Structuring code & managing dependencies for better git workflows
    • Git branching strategies for software teams
  • Conclusion & Next Steps
    • Recap of Key Concepts and Commands
    • Further Resources for Expanding Git Knowledge
    • Encouragement and Tips for Continued Learning and Practice
  • License Considerations
Powered by GitBook
On this page

Was this helpful?

  1. Working With Git
  2. Working with Git - Practice Scenarios

Working with Stash

Scenarios

Let's consider a scenario where you are working on a feature branch in your Git repository. You have made some changes to the code but haven't completed the task yet. Suddenly, you receive an urgent bug report from a user that requires your immediate attention. You need to switch to the master branch to fix the bug, but you don't want to lose your current changes on the feature branch.

To save your changes in a stash, you can use the git stash save command. Let's assume you are on the feature branch, and you want to stash your modifications:

git stash save "My work in progress"

The "My work in progress" is an optional message that you can provide to describe the stash. It helps you identify the stash later when you have multiple stashes.

After executing the command, Git will create a new stash containing your modifications and revert your working directory to the last commit. You can now safely switch to the master branch or perform any other actions.

Listing Stashes with git stash list

To see the list of stashes you have created, you can use the git stash list command. It will display the stash index, message, and the branch where the stash was created. Here's an example:

git stash list

output:

stash@{0}: On feature-branch: My work in progress
stash@{1}: On another-branch: Fixing some bugs

In this example, there are two stashes available. The most recent stash (stash@{0}) was created on the feature-branch, and the message associated with it is "My work in progress." The second stash (stash@{1}) was created on another-branch with the message "Fixing some bugs."

Applying a Stash with git stash apply

Once you are ready to continue working on your changes, you can apply the stash back to your working directory using the git stash apply command. By default, this command applies the most recent stash. If you have multiple stashes and want to apply a specific one, you can provide its index as an argument.

git stash apply

This command applies the most recent stash and brings back your changes to the working directory. If you have multiple stashes and want to apply a specific one, you can use the stash index:

git stash apply stash@{1}

The apply command doesn't remove the stash after applying it. If you want to remove the stash from the stash list, you can use the git stash drop command:

git stash drop stash@{1}

Remember to replace stash@{1} with the appropriate stash index.

Working with Git stash provides a convenient way to temporarily save your changes without committing them to the repository

PreviousExperimenting with Feature BranchesNextCloning a Repository from Remote

Last updated 1 year ago

Was this helpful?

🦕