Git常用命令

初始化仓库

指令 说明
git init 当前目录下创建一个git仓库,会生成一个.git的文件
git init [project-name] 新建一个目录,将其初始化为Git仓库
git clone url 从远程仓库拉取项目到本地

Git 配置

指令 说明
git config --list 显示当前的Git配置

git config [--global] user.name ["name"]

git config [--global] user.email ["email address"]

设置提交代码时开发者信息,--global设置全局所有项目,否则设置当前项目

分支

指令 说明
git branch 列出所有本地分支
git branch -r 列出所有远程分支
git branch -a 列出所有本地分支和远程分支
git branch [branch-name] 新建一个分支,但依然停留在当前分支
git checkout -b [branch] 新建一个分支,并切换到该分支
git checkout [branch-name] 切换到指定分支,并更新工作区
git merge [branch] 合并指定分支到当前分支
git branch -d [branch-name] 删除分支
git pull [remote] [branch] 取回远程仓库的变化,并与本地分支合并
git push [remote] [branch] 上传本地指定分支到远程仓库

已有的项目启用git

指令 说明

git init

git add

git commit -m “init”

git remote add origin url(你的远程仓库地址)

git push