Common Git Branch Names
master: Main branch, used for releasing stable versions
develop: Development branch, used for merging various feature branches
feature: Feature branch, used for developing new features
hotfix: Hotfix branch, used for fixing bugs in production
release: Release branch, used for releasing new versions
Common Git Commands
git config
git init: Initialize a local repository
git config --global user.name "yourname": Set username
git config --global user.email "youremail": Set email
git config --global core.editor "vim": Set default editor
git config --global color.ui true: Enable color
git config --list: View configuration information
git remote
git remote add origin: Add a remote repository
git remote -v: View remote repository information
git remote rm origin: Remove a remote repository
git remote set-url origin xxx: Change remote repository URL
git remote show origin: View remote repository information
git clone
git clone xxx: Clone a remote repository
git clone xxx yyy: Clone a remote repository and rename it
git clone xxx --depth=1: Clone a remote repository and fetch only the latest commit
git branch
git branch: View branches
git branch -a: View all branches
git branch -d xxx: Delete branch
git branch -D xxx: Force delete branch
git branch -m old new: Rename branch
git merge xxx: Merge branch
git rebase xxx: Rebase
git log
git log: View commit history
git log --oneline: View commit history in a concise format
git log --graph: View commit history graphically
git log --pretty=oneline: View commit history in a concise format
git log --pretty=format:"%h - %an, %ar : %s": View commit history in a custom format
git log --since=2.weeks: View commit history from the last two weeks
git log --author=xxx: View commit history of a specific author
git log --grep=xxx: View commit history containing a specific keyword
git log -p: View detailed commit history
git log -p -2: View detailed history of the last two commits
git log --stat: View commit history with brief statistics
git log --pretty=oneline --graph --all: View commit history graphically
git log --pretty=format:"%h %s" --graph: View commit history graphically
git log --pretty=format:"%h %s" --graph --all: View commit history graphically
git log --pretty=format:"%h %s" --graph --all --decorate: View commit history graphically
git log --pretty=format:"%h %s" --graph --all --decorate --oneline: View commit history graphically
git status
git status: View the status of the working directory
git status -s: View the status of the working directory in a concise format
git add
git add .: Add all files
git add xxx: Add a specific file
git add -u: Add tracked files
git commit
git commit -m "message": Commit with a message
git commit --amend: Amend the last commit
git commit --amend -m "message": Amend the last commit with a new message
git commit --amend --no-edit: Amend the last commit without changing the message
git commit --amend -m "message" --no-edit: Amend the last commit with a new message and content
git reset
git reset HEAD xxx: Unstage changes
git reset --soft HEAD^: Undo the last commit, keeping changes in the working directory
git reset --hard HEAD^: Undo the last commit and discard changes in the working directory
git reset --hard HEAD: Reset to the last commit and discard changes in the working directory
git reset --hard HEAD~3: Undo the last three commits and discard changes in the working directory
git reset --hard commit_id: Reset to a specific commit and discard changes in the working directory
git checkout
git checkout -- xxx: Discard changes in the working directory
git checkout xxx: Switch branches
git checkout -b xxx: Create and switch to a new branch
git checkout -b xxx origin/xxx: Create a new branch from a remote branch and switch to it
git checkout -b xxx commit_id: Create a new branch from a specific commit and switch to it
git stash
git stash: Stash changes in the working directory
git stash list: View stash list
git stash apply: Apply stashed changes
git stash drop: Drop a stash
git stash pop: Apply and drop a stash
git fetch
git fetch: Fetch from remote repository
git fetch origin: Fetch from remote repository
git fetch origin xxx: Fetch a specific branch from remote repository
git fetch --all: Fetch all remote repositories
git pull
git pull: Pull from remote repository and merge
git pull origin xxx: Pull a specific branch from remote repository and merge
git push
git push: Push to remote repository
git push origin xxx: Push to a specific branch in remote repository
git push origin xxx --force: Force push to a specific branch in remote repository
git push origin :xxx: Delete a specific branch in remote repository
git push origin --delete xxx: Delete a specific branch in remote repository
git push origin --tags: Push tags
git push origin --delete tag xxx: Delete a tag in remote repository
git tag
git tag: View tags
git tag xxx: Create a tag
git tag -a xxx -m "message": Create an annotated tag
git tag -d xxx: Delete tag
git show xxx: View tag information
git push origin xxx: Push tag
git push origin --tags: Push all tags
git push origin --delete tag xxx: Delete tag from remote repository
git diff
git diff: View differences between working directory and staging area
git diff HEAD: View differences between working directory and the latest commit
git diff HEAD^: View differences between working directory and the second latest commit
git diff HEAD^ HEAD: View differences between the last two commits
git diff commit_id: View differences between working directory and a specific commit
git diff commit_id1 commit_id2: View differences between two commits
git diff --cached: View differences between staging area and the latest commit
git diff --stat: View summary statistics
git diff --shortstat: View brief statistics
git diff --name-only: View changed files
git diff --name-status: View changed files and their statuses
git diff --color-words: View changes with word differences highlighted
git diff --word-diff: View changes with word differences highlighted
git diff --word-diff-regex=.: View changes with word differences highlighted using a regex
git diff --word-diff-regex=[A-Za-z0-9_]: View changes with word differences highlighted using a regex
git diff --word-diff-regex=[^[:space:]]: View changes with word differences highlighted using a regex