第一次使用
查看:
$ git config --list
修改:
$ git config --global user.name "wangyuchen"
$ git config --global user.email "email"
下载代码到本地
1)ssh方式
git clone git@github.com:buptWYChen/test.git
第一次需要配置公钥
2)https方式
第一次需要输入密码
git clone https://github.com/buptWYChen/test.git
如果想不再弹出输入密码
git clone https://username:password@github.com/buptWYChen/test.git
使用Git下载指定分支命令为:
git clone -b [branch-name] 仓库地址
分支管理
git branch 查看本地所有分支(结果列表中前面标*号表示当前使用分支)
git branch -r 查看远程所有分支
git branch -a 查看所有分支
git branch [branch-name] 新建分支
git checkout [branch-name] 切换分支
git checkout -b [branch-name] 新建分支并切换到该分支
比如:修改分支:
项目文件夹,右键git bash
$ git checkout dev
$ git pull
提交合并代码
git ststus 显示有变更的文件
git pull [remote] [branch] 取远程仓库代码到指定本地分支并合并
git add . 将工作区文件添加到暂存区
git commit -m "说明" 将暂存区文件提交至本地仓库
git push [remote] [branch] 上传本地指定分支到远程仓库
git merge [branch] 将指定分支合并至当前分支
例如,当要提交的项目中添加了新的文件:
1)先git add 把文件从工作区(workspace)添加到暂存区(Index)
$ git add app.yaml
2)再git commit 把暂存区的所有内容提交到本地仓库(Repository)
$ git commit -m "add yaml"
3)最后 git push 推到远程仓库(Remote)