Git Cheat Sheet
COMMAND
DESCRIPTION
- |git config --global user.name|Set global username.
- |git config --global user.email|Set global email.
- |git init|Initialize a new repository.
- |git clone url|Clone a remote repository.
- |git status|Show working tree status.
- |git log|Show commit history.
- |git log --oneline|Compact commit history.
- |git log --oneline --graph|Visual branch graph.
- |git diff|Show unstaged changes.
- |git diff --staged|Show staged changes.
- |git blame file|Show line-by-line authorship.
- |git reflog|Show all ref history.
- |git shortlog -sn|Commit counts by author.
- |git add file|Stage a file.
- |git add .|Stage all changes.
- |git add -p|Stage changes interactively.
- |git restore --staged file|Unstage a file.
- |git restore file|Discard working tree changes.
- |git commit -m "msg"|Commit with a message.
- |git commit --amend|Amend the last commit.
- |git branch|List local branches.
- |git branch name|Create a branch.
- |git branch -d name|Delete a branch.
- |git switch name|Switch to a branch.
- |git switch -c name|Create and switch to branch.
- |git merge name|Merge a branch into current.
- |git cherry-pick sha|Apply a specific commit.
- |git revert sha|Revert a commit safely.
- |git remote -v|List remotes.
- |git remote add name url|Add a remote.
- |git fetch|Fetch remote changes.
- |git pull|Fetch and merge changes.
- |git push|Push commits to remote.
- |git push -u origin name|Push and set upstream.
- |git push --force-with-lease|Safe force push.
- |git stash|Stash working tree changes.
- |git stash pop|Apply and remove latest stash.
- |git stash list|List all stashes.
- |git stash drop|Delete the latest stash.
- |git rebase branch|Rebase onto a branch.
- |git rebase -i HEAD~n|Interactive rebase.
- |git reset HEAD~1|Undo last commit, keep changes.
- |git reset --hard HEAD~1|Undo last commit, discard all.
- |git clean -fd|Remove untracked files/dirs.
- |git tag v1.0.0|Create a lightweight tag.
- |git tag -a v1.0.0 -m "msg"|Create an annotated tag.
- |git push --tags|Push all tags to remote.
- |git bisect start|Start binary search for bug.