参考:常用 Git 命令清单
1、常用名词
- Workspace:工作区
- Index/Stage: 暂存区
- Repository:仓库区(或者本地仓库)
- Remote: 远程仓库
2、新建代码库
$ git init // 在当前目录新建一个Git代码库
3、配置
$ git config
4、增加删除文件
$ git add // 添加当前目录的所有文件到暂存区
5、代码提交
$ git commit // 提交暂存区的文件到仓库区
6、分支
$ git branch // 列出所有本地分支
7、远程同步
$ git fetch [remote] // 下载远程仓库的所有变动
$ git remote // 显示所有远程仓库
$ git pull [remote] [branch] // 取回远程仓库的变化,并与本地分支合并
$ git push [remote] [branch] // 上传本地指定分支到远程仓库
$ git push [remote] --force // 强行推送当前分支到远程仓库,即使有冲突
8、撤销
$ git checkout // 恢复暂存区的所有文件到工作区