项目经验,如需转载,请注明做者:Yuloran (t.cn/EGU6c76)git
Android 开发中经常使用的版本控制工具就是 Git
。商业项目大多使用 Git Server
+ Git Client
+ Gerrit
+ Jenkins
搭建代码审核及持续集成系统。我的开源项目大多托管在 GitHub
(免费 Git 服务器)。因此,本文以 GitHub
为例,简述 Git
帐户配置及命令行中 Git
命令别名配置。github
先下载 Git for windows,而后安装。安装结束后,按 Win + R 键,输入 cmd 打开命令行窗口,输入 git 回车,看是否有以下提示:windows
没有的话,须要将 D:\Program Files\Git\cmd
(替换为你本身的文件路径)配置到环境变量中。这样就能够在 windows cmd 中使用 git 命令,不然只能右键打开 Git Bash,在 Git Bash 中使用 Git 命令。bash
Git 使用 SSH 协议验证和登陆远程服务器,因此首先须要生成 SSH Key,并把 Public Key 添加到 GitHub 帐户。服务器
按 Win + R 输入 cmd,打开命令行,输入如下命令,而后回车:ssh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
工具
检查是否生成:测试
用记事本打开 id_rsa.pub,将文件中全部内容复制到下图所示位置并保存:spa
ssh -T git@github.com
[] 表示参数可选,--global 表示全部项目都使用这个邮箱提交代码,而不加这个参数,则能够为不一样项目配置不一样的邮箱。命令行
git config [--global] user.name "your_name"
git config [--global] user.email your_email@example.com
查看配置:
git config --list
配置命令别名后,只用敲 git co 就能够代替原来的 git checkout,省事很多。
敲 cls 清屏:编辑D:\Program Files\Git\etc\profile.d\aliases.sh
,添加alias cls='clear'
git 经常使用命令别名配置:
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.br branch
git config --global alias.last 'log -1'
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
复制代码
能够参考 廖雪峰的Git教程,通俗易懂。