DEV Community

Discussion on: 6 Git commands every beginner should memorize

Collapse
 
exadra37 profile image
Paulo Renato • Edited

You forgot the most important of all git checkout -:

╭─exadra37@approov ~/Developer/Approov2/blog/shipfast-on-docker  ‹approov2-new-rebased› 
╰─➤  git checkout -
Switched to branch 'approov2-new'
╭─exadra37@approov ~/Developer/Approov2/blog/shipfast-on-docker  ‹approov2-new› 
╰─➤  git checkout -
Switched to branch 'approov2-new-rebased'

It's just like our old Linux friend cd - ;)

Ok, the above one is more a tip, but a very important command to know about for beginners is git stash --help and git show --help

With git stash we can save our changes that are not commited yet, and if we include -u we will save also the files not tracked. It's useful to clear the workspace or to move code not committed yet to another branch or just to later reuse on the same branch, just by doing git stash apply.

With git show we can see the git diff for the last commit, and with git show <commit-hash> or git show HEAD~3 we see the git diff for that specific point in history.

When things go terrible wrong, like you delete accidentally a branch, you can use git reflog --help to see your history of changes and get back to a good state.

Collapse
 
axadream profile image
Alex Pintea

Very useful tips.Thanks a lot, especially for the idea to use git stash apply

Collapse
 
jeremy profile image
Jeremy Schuurmans

Agreed! These are awesome tips. Thank you!