I do use some GUI to run git, but for most basic and simple actions I prefer using cli as it is way faster. Here is a summary of my most used git commands.
Create a new branch and tracking remote branch
git checkout -b branch_name origin/branch_name
See status
git status
Stage a file
git add file_name
Unstage a single file
git reset file_name
Stage all files
git add .
Unstage all files
git reset
Discard un-staged changes of a single file
git checkout file_name
Discard all un-staged/staged changes
git reset --hard
Commit staged changes
git commit -m 'commit message'
Add and commit all changes in one step
git commit -am 'message'
Diff between un-staged files and staged files
git diff
Diff between staged files and HEAD
git diff --cached
See commits
git log
Diff between HEAD and its previous commit
git diff @^ @
Diff between any commit and its previous commit
git diff commit_hash^ commit_hash
Reset to a commit and keep the changes un-staged
git reset commit_hash
Reset to a commit and discard the changes
git reset commit_hash --hard
As always: bonus
Add change to the previous commit but without having a new commit
git commit --amend --no-edit
That's it. Hope you enjoy it!
Top comments (1)
Great! Thanks for sharing.