A
AiTechWorlds
AiTechWorlds
All git commands you actually need init, commit, branch, merge, rebase, reset and more.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor "code --wait"
git config --list # view all configgit init # new repo in current folder
git clone <url> # clone remote repo
git clone <url> my-folder # clone into specific foldergit status # check what changed
git diff # unstaged changes
git diff --staged # staged changes
git add file.txt # stage specific file
git add . # stage all changes
git add -p # stage hunks interactively
git commit -m "message" # commit with message
git commit --amend # edit last commit (local only!)git branch # list branches
git branch -a # list all (including remote)
git branch feature/login # create branch
git checkout feature/login # switch to branch
git checkout -b feature/login # create + switch
# Modern syntax (Git 2.23+)
git switch feature/login # switch branch
git switch -c feature/login # create + switch
git branch -d feature/login # delete merged branch
git branch -D feature/login # force delete# Merge
git checkout main
git merge feature/login # merge feature into main
git merge --no-ff feature/login # preserve merge commit
# Rebase
git checkout feature/login
git rebase main # rebase onto main
# Interactive rebase (last 3 commits)
git rebase -i HEAD~3
# Options: pick, squash, reword, dropgit remote -v # list remotes
git remote add origin <url> # add remote
git remote remove origin # remove remote
git fetch origin # download without merge
git pull origin main # fetch + merge
git pull --rebase origin main # fetch + rebase
git push origin main # push to remote
git push -u origin feature/login # push + set upstream
git push --force-with-lease # safer force push# Unstage file (keep changes)
git restore --staged file.txt
# Discard changes in working directory
git restore file.txt
# Undo last commit (keep changes staged)
git reset --soft HEAD~1
# Undo last commit (keep changes unstaged)
git reset HEAD~1
# Undo last commit (discard changes!)
git reset --hard HEAD~1
# Revert a commit (creates new commit)
git revert abc1234git stash # save changes temporarily
git stash push -m "work in progress"
git stash list # view stashes
git stash pop # apply + remove stash
git stash apply stash@{0} # apply without removing
git stash drop stash@{0} # delete a stash
git stash clear # delete all stashesgit log # full history
git log --oneline # compact view
git log --oneline --graph # with branch graph
git log -10 # last 10 commits
git log --author="John" # filter by author
git log --since="2024-01-01" # since date
git log -- file.txt # history of a file
git show abc1234 # show commit details
git blame file.txt # line-by-line authorshipgit tag # list tags
git tag v1.0.0 # lightweight tag
git tag -a v1.0.0 -m "Release" # annotated tag
git push origin v1.0.0 # push tag
git push origin --tags # push all tags
git tag -d v1.0.0 # delete local tag# Search commits
git log --grep="fix bug"
# Cherry-pick a commit
git cherry-pick abc1234
# Clean untracked files
git clean -fd
# Show file at specific commit
git show abc1234:src/file.tsnode_modules/ # ignore folder
*.log # ignore by extension
.env # ignore specific file
dist/ # ignore build output
!important.log # exception: track thisgit checkout -b feature/new-feature main
# ... make changes ...
git add . && git commit -m "Add new feature"
git push -u origin feature/new-feature
# Create PR on GitHub/GitLab
git checkout main && git pullgit add forgotten-file.txt
git commit --amend --no-editGet more notes like this daily on Telegram!
Free study notes, cheat sheets & AI tips
Last reviewed on June 13, 2026 by the AiTechWorlds Notes Team. Free cheat sheet no signup required.
Join AiTechWorlds on Telegram and get daily AI tips, prompt engineering templates, coding resources, and exclusive content 100% free!
No spam. Leave anytime.