Git Cheatsheet
Common Git commands and usage.
Setup
git config --global user.name "name"Set global username
git config --global user.email "email"Set global email
git initInitialize a new repository
git clone <url>Clone a repository
Changes
git statusCheck status of working directory
git add <file>Add file to staging area
git add .Add all files to staging area
git commit -m "msg"Commit staged changes
git commit --amendModify last commit
Branching
git branchList branches
git branch <name>Create new branch
git checkout <name>Switch to branch
git checkout -b <name>Create and switch to branch
git merge <branch>Merge branch into current
git branch -d <name>Delete branch
Syncing
git remote -vList remotes
git fetchFetch changes from remote
git pullFetch and merge changes
git pushPush changes to remote
git push -u origin <branch>Push new branch to remote
Undoing
git reset <file>Unstage a file
git checkout -- <file>Discard changes in file
git revert <commit>Create new commit reversing changes
git reset --hard <commit>Reset to commit (destructive)
Log
git logShow commit history
git log --onelineShow compact history
git diffShow unstaged changes
git show <commit>Show changes in commit
What is Git?
Git is a distributed version control system that tracks changes in source code during software development.
This cheatsheet provides quick access to essential Git commands for branching, merging, committing, and collaborating with other developers.