Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 1.53 KB

File metadata and controls

78 lines (56 loc) · 1.53 KB

Git Basic Commands

English | 中文

Create or clone

git init
git clone <url>

Check status

git status
git log --oneline --decorate

Stage and commit

git add <file>
git commit -m "docs: add git basics"

Sync

git fetch
git pull --rebase
git push

Branch

git switch -c feat/my-task
git switch main
git branch

Undo

git restore <file>
git restore --staged <file>
git revert <commit-sha>

Recommended Practice Sequence

  1. Use git status to understand the current state.
  2. Use git add and git commit to complete one local commit.
  3. Use git switch -c to create a task branch.
  4. Use git diff to check changes before committing.
  5. Use git push to push the branch and create a PR.
  6. Use git restore to undo local changes.

Don't Rush to Use High-Risk Commands

Use with caution during the novice stage:

git reset --hard
git push --force
git clean -fd

These commands may directly discard local changes or rewrite remote history.

If you just want to undo ordinary workspace changes, prioritize learning Undo Anything.

Extended Reading