項目經驗,如需轉載,請註明做者: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教程,通俗易懂。