Git Cheat Sheet
01 Aug 2022 - Alejandro Piña
Basic git commands that are used day to day
Working with branches
Switchs to a given branch
-b
creates a branch if not exists
git checkout -b mybranch
List all local branches
git branch
Delete branches
git branch -D <branch_name> #delete local branch
git push origin :<branch_name> #delete remote branch
View graph with basic information including commit short ID
git log --all --decorate --online --graph
You can wrap graph command in a short command with an alias e.g.
echo "alias gitgraph='git log --all --decorate --oneline --graph'" >> ~/.bash_aliases
Working with commits
Revert changes
--soft
reverts changes to stagging area--mixed
reverts changes to working directory preserving modifications--hard
reverts changes including modifications
git reset --soft <commit_short_id>
git push origin HEAD --force
Reorganizes current branch commits after HEAD <branch_name>
, make sure that you fetched your braches before this operation
git rebase <branch_name>
Logs
Shows information about the commit like modifications and author
git show <commit_short_id>
Shows who mades the modifications line by line
-L
shows part of the content<from,to>
git blame <filename> -L 0,10