一、初始化仓库
# 新建一个目录,将其初始化为Git代码库
git init [project-name]
# 下载一个项目和它的整个代码历史
git clone [url]
二、工作区-->暂存区
# 添加指定文件到暂存区
git add [file1] [file2] ...
# 添加当前目录的所有文件到暂存区
git add .
# 从暂存区删除到工作区
git rm --cached <file>...
三、暂存区-->仓库区
git commit -m "message..."
四、分支
# 列出所有本地分支和远程分支
git branch -a
# 新建一个分支,但依然停留在当前分支
git branch [branch-name]
# 新建一个分支,并切换到该分支
git checkout -b [branch]
# 切换到指定分支,并更新工作区
git checkout [branch-name]
# 删除分支
git branch -d [branch-name]
五、远程同步
# remote为url地址,或者本地起到别名 branch为本地分支名
# 为远程地址起名
git remote add [<options>] <name> <url>
# 取回远程仓库的变化,并与本地分支合并
git pull [remote] [branch]
# 上传本地指定分支到远程仓库
git push [remote] [branch]
# 列出所有远程别名
git remote -v
六、查看信息
# 显示有变更的文件
git status
# 显示当前分支的版本历史
git log