Imagine you are writing some new feature in feature/cool-feature branch and then suddenly a small bug appears and you need to solve it quickly so you need to move to integration branch for the fix to be solved and pushed on time.
Well this command comes in handy for when you’re not ready for a commit yet but don’t want to lose changes by moving to another branch. By executing this command every change on the working directory will be saved and the project state will be returned to the last commit so you can move now to integration and work on the bug fix.
When you’re ready to come back and work on the feature just move back to feature/cool-feature and execute
git stash pop or
git stash apply whichever suits you. Right after every change you had before will be there and you will be able to continue where you left off.
git checkout -b branch-name
This is another way of executing both
git branch branch-name and
git checkout branch-name. It creates and moves you to the just created branch.
git log --oneline --graph
Want to see the commits history? Try this command to see a nice compact list of the commits.
git checkout HEAD <filename>
If you deleted a file by mistake and haven’t done a commit yet this will get your file back.
git commit --amend
You’ve just made a commit and realized it had a typo. This will help you to fix the typo, allowing you to edit the last commit’s message.