git

git

远程

推送本地项目到远程仓库  

git init 
git add .
git commit -m "first_commit"
git remote add origin <远程仓库地址>
git push -u origin "main"

重新设置远程仓库

git remote set-url origin <远程仓库地址>

查看远程地址别名及路径

git remote -v

查看工作区、暂存区的状态(哪些文件被修改/未跟踪)

git status

更新 .gitignore

git rm -r --cached .
git add .
git commit -m 'update .gitignore'

分支管理

查看本地分支列表,-a 查看所有分支(含远程)

git branch

创建新分支

git branch <分支名>

切换到指定分支(switch 是更直观的新命令)

git checkout <分支名>
或
git switch <分支名>

  创建并切换到新分支。  

git checkout -b <新分支名>
或
git switch -c <新分支名>

将指定分支合并到当前分支

git merge <分支名>

将当前分支的提交变基到目标分支

git rebase <分支名>

删除本地分支;-D 强制删除未合并的分支。

git branch -d <分支名>

git
https://mingsm17518.github.io/2026/03/05/常用命令/git/
作者
Ming
发布于
2026年3月5日
更新于
2026年3月5日
许可协议