创建仓库
使用当前目录作为 Git 仓库,我们只需使它初始化
git init
使用我们指定目录作为Git仓库。
git init newrepo
从项目库中拷贝项目到指定项目
如果我们需要克隆到指定的目录,可以使用以下命令格式:
git clone <repo> <directory>
示例:`git clone git@192.168.1.145:testgroup/qualityMonitor.git E://代码//project
设置提交代码时的用户信息:
git config --global user.name "runoob"
git config --global user.email test@runoob.com
如果去掉 --global 参数只对当前仓库有效。
分支管理
创建分支
git branch (branchname)
切换分支命令
git checkout (branchname)
查看本地所有分支
git branch
将master分支代码合并到当前分支
- 切换到当前分支
git merge master
删除分支命令:
git branch -d (branchname)
删除提交 add命令后悔药:
git rm --cached file
一般操作步骤
- 提交修改文件到暂存区
git add filename
filename为“.”表示提交整个项目 - 提交暂存区到本地仓库并加以注释
git commit -m "提交测试"
- 查看仓库当前的状态,显示有变更的文件
git status
- 提交本地分支到线上,
git push
- 一般提交之前会先拉取线上代码更新到本地(防止别人更新的代码和自己更改的有冲突,需要本地解决之后提交到线上)
git pull