Git Commands Cheat Sheet

The essential Git commands for day to day version control


Setup and cloning

git init                 # start a new repository
git clone URL            # copy a remote repository
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Daily workflow

git status               # what changed
git add .                # stage all changes
git commit -m "message"  # commit staged changes
git push                 # push to remote
git pull                 # pull latest from remote

Branching and merging

git branch               # list branches
git branch name          # create a branch
git checkout name        # switch to a branch
git checkout -b name     # create and switch
git merge name           # merge a branch into current
git branch -d name       # delete a branch

History and undo

git log --oneline        # compact history
git diff                 # unstaged changes
git show COMMIT          # show a commit
git stash                # set changes aside
git stash pop            # restore stashed changes
git revert COMMIT        # undo a commit safely
git reset --hard HEAD    # discard all local changes

Remotes

git remote -v                          # list remotes
git remote add origin URL              # add a remote
git push -u origin main                # push and set upstream