This document contains frequently used Git commands for common development tasks.
git config --global user.name "[name]"
git config --global user.email "[email]"git config --listgit branch <branch-name>git checkout -b <branch-name>
# or (Git 2.23+)
git switch -c <branch-name>git branchgit branch -agit checkout <branch-name>
# or (Git 2.23+)
git switch <branch-name>git branch -d <branch-name>
# Force delete (if not merged)
git branch -D <branch-name>git push origin --delete <branch-name># Rename current branch
git branch -m <new-branch-name>
# Rename specific branch
git branch -m <old-branch-name> <new-branch-name>git statusgit add .git add <file-path>git reset <file-path>git commit -m "<type>(<scope>): <subject>"git commit
# Opens editor for multi-line commit messagegit commit --amend
# Without changing commit message
git commit --amend --no-editgit log
# One line per commit
git log --oneline
# With graph visualization
git log --graph --oneline --allgit remote -vgit remote add <remote-name> <repository-url>git remote remove <remote-name>git remote rename <old-name> <new-name>git remote show <remote-name>git push <remote-name> <branch-name>
# Example
git push origin feature/src_v2_app_commentsgit push <remote-name> --allgit push -u <remote-name> <branch-name>git pull <remote-name> <branch-name>git fetch <remote-name>git push --force <remote-name> <branch-name>
# Safer alternative
git push --force-with-lease <remote-name> <branch-name>git stash
# With description
git stash save "<description>"git stash listgit stash apply
# Apply specific stash
git stash apply stash@{0}git stash popgit stash drop stash@{0}git merge <branch-name>git rebase <branch-name>git merge --abort
git rebase --abortgit diffgit diff --stagedgit diff <file-path>git diff <branch-1> <branch-2>git checkout -- <file-path>
# or (Git 2.23+)
git restore <file-path>git reset --hard HEADgit revert <commit-hash># Soft reset (keep changes staged)
git reset --soft HEAD~1
# Mixed reset (keep changes unstaged)
git reset --mixed HEAD~1
# Hard reset (discard changes)
git reset --hard HEAD~1Add these to your Git config for faster commands:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
git config --global alias.visual 'log --graph --oneline --all'git checkout -b feature/src_v2_app_comments
# Make changes
git add .
git commit -m "feature(src_v2_app_comments): add new feature"
git push -u origin feature/src_v2_app_commentsgit fetch origin
git rebase origin/main
# or merge
git merge origin/main# Delete merged branches
git branch --merged | grep -v "\*" | xargs -n 1 git branch -dgit fetch upstream
git checkout main
git merge upstream/main
git push origin main