Once you master commit and push, it’s time to upgrade your workflow to handle branches, temporary changes, and history reviews.
1. Branch Management (Modern vs Classic)
Creating and switching branches is essential to keep main clean.
git switch -c feature/new-feature # Create and switch
git switch main # Return to maingit switch -c feature/new-feature # Create and switch
git switch main # Return to main2. Temporary Storage (Stash)
Have halfway changes but need to switch branches urgently? Don’t commit broken code, put it in your “pocket”.
git stash # Save changes and clean directory
git stash pop # Recover latest saved changes
git stash list # List all stashed changesgit stash # Save changes and clean directory
git stash pop # Recover latest saved changes
git stash list # List all stashed changes3. Readable History
Viewing the default history log can be overwhelming.
git log --oneline --graph --all # Compact visual treegit log --oneline --graph --all # Compact visual tree4. Undoing Changes
git restore file.txt # Discard local changes
git restore --staged file.txt # Unstage changesgit restore file.txt # Discard local changes
git restore --staged file.txt # Unstage changes