Git 命令速查表

2025-05-27

Git 命令速查表

你好,Dev,

我们都知道Git,但我想分享一些关于它的内容,在我日常使用中,它是所有开发人员都需要的基本备忘单。

我们团队合作完成项目时,经常发生代码冲突。当时我们决定在办公室桌子上方的墙上贴一张小抄。

Git克隆:

git clone https://name-of-the-repository-link
Enter fullscreen mode Exit fullscreen mode

Git 新建分支、列出、删除:

git branch -b (branch name)
git branch or git branch --list
git branch -d 
Enter fullscreen mode Exit fullscreen mode

Git 结帐:

git checkout (branch name)
Enter fullscreen mode Exit fullscreen mode

Git Switch:
git switch 表示您已经创建了分支。

git switch (branch name) 
Enter fullscreen mode Exit fullscreen mode

Git 状态命令:
如当前分支、提交、推送或拉取、文件暂存、未暂存或未跟踪、文件创建、修改或删除

git status
Enter fullscreen mode Exit fullscreen mode

Git 添加:

git add 
git add -A (for everything)
Enter fullscreen mode Exit fullscreen mode

Git 提交:

git commit -m "commit message"
Enter fullscreen mode Exit fullscreen mode

Git Push:用于上传本地 repo 内容

  1. git push:通常用于将本地仓库内容上传到远程仓库。
  2. git push --set-upstream:设置分支“branch Name”以从“origin”跟踪远程分支“branch Name”。
  3. git push -u origin:用于推送现有工作分支。
git push 
git push --set-upstream 
git push -u origin
Enter fullscreen mode Exit fullscreen mode

Git Pull:用于从本地仓库获取合并分支

git pull
Enter fullscreen mode Exit fullscreen mode

Git Merge:将分支合并到另一个

git checkout (branch name)
git fetch
git merge
Enter fullscreen mode Exit fullscreen mode

感谢您的阅读。

文章来源:https://dev.to/anitaparmar26/git-command-cheat-sheet-31ec
PREV
Windows 终端主题美化你的 Windows 终端🦄
NEXT
我为什么选择 Angular