git init
Initialize a new Git repository in the current directory
git clone <repo_url>
Download a repository from a remote server
git status
Show changed, staged, and untracked files
git log
Show commit history
git log --oneline --graph --all
Compact graphical view of commit history
git show <commit_hash>
Show details of a specific commit
git diff
Show unstaged file differences
git diff --staged
Show staged changes
git blame <file>
Show who modified each line in a file
git add <file>
Stage a specific file
git add .
Stage all changes in the current directory
git commit -m "message"
Create a commit with staged changes
git commit -am "message"
Commit all tracked files quickly
git branch
List local branches
git branch -r
List remote branches
git branch -a
List all branches (local and remote)
git branch --show-current
Show the current branch name
git branch -vv
Show branch tracking information
git branch <branch_name>
Create a new branch
git branch -d <branch_name>
Delete a merged branch
git branch -D <branch_name>
Force delete a branch
git switch <branch>
Switch to another branch
git switch -c <branch>
Create and switch to a new branch
git checkout <branch>
Switch branch (older command)
git checkout -b <branch>
Create and switch branch (older method)
git remote -v
Show remote repository URLs
git remote add origin <repo_url>
Add a remote repository
git remote remove origin
Remove a remote repository
git fetch
Download remote changes without merging
git fetch origin
Fetch updates from specific remote
git pull
Fetch and merge changes from remote
git pull origin main
Pull changes from main branch
git pull --rebase origin main
Pull changes using rebase instead of merge
git push
Push commits to remote
git push origin <branch>
Push a specific branch
git push -u origin <branch>
Push and set upstream tracking
git push --force-with-lease
Safely force push changes
git push --tags
Push all tags to remote
git merge <branch>
Merge a branch into the current branch
git merge --no-ff <branch>
Merge while keeping branch history
git merge --abort
Cancel an ongoing merge
git rebase <branch>
Reapply commits on top of another branch
git rebase origin/main
Rebase onto the latest remote main
git rebase -i HEAD~3
Interactive rebase for the last 3 commits
git rebase --continue
Continue rebase after resolving conflicts
git rebase --abort
Cancel rebase operation
git stash
Save current work temporarily
git stash list
Show saved stashes
git stash pop
Restore the most recent stash
git restore <file>
Restore file to last committed state
git reset <file>
Unstage a staged file
git reset
Unstage all staged files
git reset --soft HEAD~1
Undo last commit but keep changes
git reset --hard HEAD
Reset repository to last commit (discard changes)
git cherry-pick <commit_hash>
Apply a specific commit to the current branch
git tag <tag_name>
Create a new tag
git push origin <tag_name>
Push a tag to remote
git clean -f
Remove untracked files
git clean -fd
Remove untracked files and directories