Setup
git initInitialize a new Git repository
Example:
git initgit clone [url]Clone a repository from remote
Example:
git clone https://github.com/user/repo.gitBasic
git statusCheck status of working directory
Example:
git statusgit add [file]Stage file for commit
Example:
git add index.htmlgit add .Stage all changes
Example:
git add .git commit -m "[message]"Commit staged changes
Example:
git commit -m "Add new feature"Remote
git push origin [branch]Push commits to remote
Example:
git push origin maingit pullFetch and merge changes from remote
Example:
git pullBranching
git branchList all branches
Example:
git branchgit branch [name]Create a new branch
Example:
git branch feature-logingit checkout [branch]Switch to a branch
Example:
git checkout developgit merge [branch]Merge branch into current branch
Example:
git merge feature-loginHistory
git logView commit history
Example:
git log --onelinegit diffShow changes between commits
Example:
git diff HEAD~1Advanced
git reset --hard [commit]Reset to a specific commit
Example:
git reset --hard HEAD~1git stashSave changes for later
Example:
git stash save "work in progress"git stash popApply stashed changes
Example:
git stash popgit rebase [branch]Reapply commits on top of another base
Example:
git rebase mainRelated Resources
2 itemsCompare Options
Use Tools
Frequently Asked Questions
How do I use this git cheatsheet?
Simply find the command you need, click the copy button to copy it to your clipboard, and paste it into your terminal or code editor. Each command includes a description and example to help you understand its usage.
Can I download this cheatsheet?
Currently, this cheatsheet is available online. You can bookmark this page for quick access.