1.在当前目录新建一个Git代码库
git init
2.新建一个目录,将其初始化为Git代码库
git init [project-name]
3.下载一个项目
git clone [url]
4.显示当前的Git配置
git config --list
5.编辑Git配置文件
git config -e [--global]
6.设置提交代码时的用户信息
git config [--global] user.name "[name]"
git config [--global] user.email "[email address]"
7.添加指定文件到暂存区
git add [file1] [file2] ...
8.添加指定目录到暂存区,包括子目录
git add [dir]
9.添加当前目录的所有文件到暂存区
git add .
10. 删除工作区文件,并且将这次删除放入暂存区
git rm [file1] [file2] ...
11.停止追踪指定文件,但该文件会保留在工作区
git rm --cached [file]
12. 改名文件,并且将这个改名放入暂存区
git mv [file-original] [file-renamed]
13.提交暂存区到仓库区
git commit -m [message]
14.提交工作区自上次commit之后的变化,直接到仓库区
git commit -a
15.提交时显示所有diff信息
git commit -v
16.重做上一次commit,并包括指定文件的新变化
git commit --amend [file1] [file2] ...
17.列出所有本地分支
git branch
18.列出所有远程分支
git branch -r
19.列出所有本地分支和远程分支
git branch -a
20.新建一个分支,但依然停留在当前分支
git branch [branch-name]
21.新建一个分支,并切换到该分支
git checkout -b [branch]
22.新建一个分支,指向指定commit
git branch [branch] [commit]
23. 切换到指定分支,并更新工作区
git checkout [branch-name]
24.切换到上一个分支
git checkout -
25.合并指定分支到当前分支
git merge [branch]
26.删除分支
git branch -d [branch-name]
27.删除远程分支
git push origin --delete [branch-name]
git branch -dr [remote/branch]
28.查看tag信息
git show [tag]
29. 显示有变更的文件
git status
30.显示当前分支的版本历史
git log
31.显示commit历史,以及每次commit发生变更的文件
git log --stat
32.下载远程仓库的所有变动
git fetch [remote]
33.显示所有远程仓库
git remote -v
34.显示某个远程仓库的信息
git remote show [remote]
35.增加一个新的远程仓库,并命名
git remote add [shortname] [url]
36.取回远程仓库的变化,并与本地分支合并
git pull [remote] [branch]
37.上传本地指定分支到远程仓库
git push [remote] [branch]
38.推送所有分支到远程仓库
git push [remote] --all
39.恢复暂存区的指定文件到工作区
git checkout [file]
40.恢复暂存区的所有文件到工作区
git checkout .
41.重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变
git reset [commit]