Git 命令备忘单

常见 Git 命令的综合备忘单,包括分支、提交、合并。

Init & Config
git init

Initialize a new Git repository

Init & Config
git clone <url>

Clone an existing repository into a new directory

Init & Config
git config --global user.name "Name"

Set the author name to be attached to your commits

Init & Config
git config --global user.email "email"

Set the author email to be attached to your commits

Changes
git status

Show the status of the repository

Changes
git add .

Add all current changes to the next commit

Changes
git commit -m "msg"

Commit the staged files with a message

Changes
git diff

Show changes between commits, commit and working tree, etc

History
git log

Show commit logs

History
git log --oneline

Show commit logs in a single line

Branches
git branch

List all local branches

Branches
git branch <branch>

Create a new branch

Branches
git checkout <branch>

Switch to a different branch

Branches
git checkout -b <branch>

Create a new branch and switch to it

Branches
git merge <branch>

Merge the specified branch's history into the current one

Remote
git remote add origin <url>

Add remote repository

Remote
git push -u origin <branch>

Push changes to remote repository

Remote
git pull

Fetch from and integrate with another repository or a local branch

Remote
git fetch

Download objects and refs from another repository

Reset
git reset --hard HEAD

Reset current HEAD to the specified state