Code something else without commit
What if you’re working on a ticket, feature or fix; suddenly, the tech lead approaches and say: “Martínez, an urgent bug raised from the previous release, it needs to be fixed asap”… you know it’s a quick and easy fix, the problem is, you don’t want to do a commit of half-done work so you can get back to this point later. The answer to this issue is the git stash command.
What stash does is it pushes into one local stack the unfished state of your working directory. Yes, it’s a stack, it means you can pop it later to continue your work exactly where you left it.
Simple steps
1. Once in your working branch and directory type: git stash, now your work was “safely” stored and stashed in your computer
2. git status, just to confirm there’s nothing to commit
3. git checkout <desire branch>, you can switch to the require branch
4. Perform and commit the urgent requested changes
5. git checkout <previous working branch>, once you get back to your normal work, switch to such branch
6. git stash list, it will show you all the stashes stored in your local stack
7. git stash apply, it applies the most recent stash stored, moving back your working directory and branch status to the exact point where you left it
8. Now you can happily finish your ticket
Use the link bellow to get more information about stash command variations.
Reference: https://git-scm.com/book/en/v1/Git-Tools-Stashing