1 安裝Xcode
安裝Homebrew之前,需要安裝Xcode Comand Line Tools:
xcode-select --install
2 安裝Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝完成后,Homebrew的主程序安裝在/usr/local/bin/brew,在目錄/usr/local/Library/Formula/下保存了所有Homebrew支持的軟件的安裝指引文件。
3 使用Homebrew安裝Git
brew install git
使用Homebrew方式安裝,Git被安裝在/usr/local/Cellar/git/2.21.0路徑下。
安裝完成后,使用如下命令查看Git版本:
git --version
4 配置GitHub中的SSH key值
4.1 輸入如下命令產生新的key
ssh-keygen -t rsa -C "your_email@example.com"
4.2 將SSH key添加到Github
登錄到Github頁面 -> 右上角Setttings -> SSH keys ->Add key
查看生成的key內容:
cat ~/.ssh/id_rsa.pub
將以上內容復制到Key所對應的輸入框中並保存。
詳見:Github的搭建和配置github中的SSH key值
5 配置Git用戶信息
git config --global user.name "你的名字或昵稱" git config --global user.email "你的郵箱"
6 提交第一行代碼
git clone https://gitlab.testgu.com/ycyzharry/HelloGit.git #將遠程倉庫克隆到本地 git add . #將當前目錄所有文件添加到git暫存區 git commit -m "my first commit" #提交並備注提交信息 git push origin master #將本地提交推送到遠程倉庫