一、基本设置
在安装完 Git 之后,需要运行以下两句命令
git config [--global] user.name "John Doe"
git config [--global] user.email johndoe@example.com
如果不想每次 pull|push 操作都输入用户名、密码则添加以下设置
git config [--global] credential.helper store
二、本地库(仓库)[init|clone]
新建仓库:
创建一个目录,在目录中执行
git init
克隆仓库:
git clone <remote|local> [pathname]
remote: 远程库地址
local: 本地库地址
pathname: 检出路径(默认为当前目录)
三、文件[add|commit]
文件状态:
Untracked: 未跟踪
Unmodified: 未修改
Modified: 已修改
Staged: 已暂存
将未跟踪(Untracked)或已修改文件(Modified)放入暂存区(Staged):
git add <.|pathname>...
.: 所有文件
pathanme: 文件路径
将暂存区(Staged)的文件保存(未修改状态:Unmodified)
git commit <-m message>
-m message: 本次提交信息
四、分支[branches|checkout]
1、分支新建:
git branch <branch_name>
2、分支切换:
git checkout <branch_name>
3、分支列表:
git branch [-a]
4、分支重命名:
git branch (-m | -M) [<oldbranch>] <newbranch>
5、分支合并:(将指定分支合并到当前分支)
git merge <branchname>…
6、分支删除:(将被合并的分支删除)
git branch (-d | -D) [-r] <branchname>…
五、远程库(远程)[remote]
1、查看远程库
git remote [-v | --verbose]
2、添加远程库:
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=<fetch|push>] <name> <url>
3、重命名远程库分支
git remote rename <old> <new>
4、删除远程库
git remote remove <name>
六、拉取[pull]
git pull <remote:branche> <local_branche>
七、推送[push]
git push [-u] <remote:branche> <local_branche>
更多基本命令行操作参考https://git-scm.com/book/zh/v2
来源:oschina
链接:https://my.oschina.net/u/2647760/blog/1813521