# git v.s github簡介與實作 ## 學習目標 - 什麼是git - 安裝git - git常用指令 - 什麼是github - 認識github,註冊gitub帳號 - 產生ssh key上傳到github,讓github認識你的電腦 - github上創造一個Repository(repo) ## 什麼是github? 什麼是git ![](https://i.imgur.com/3pnIcdH.png) ## git - 是個軟體 - 用command line 操作 - 可以讓多個開發者一起開發協作 - 是個分散式版本控制系統, - 讓你回到歷史紀錄的某一時刻 因為每次不論由computerA或computerB的提取及操作,都是將那個版本直接copy下來,所以只要任何一處協同工作用的伺服器發生故障,事後都可以用任何一個本地倉庫進行恢復。 ![](https://i.imgur.com/2b15zad.png) 圖文網址:https://kknews.cc/code/4vvmvv.html ### git常用指令 [command line 常用指令傳送門](https://hackmd.io/@chrislinlin/git_command) ### 安裝git 1. 利用mac本身的開發者工具 ![](https://i.imgur.com/eRzgSsV.png) 2. 點進去,輸入 `brew install git` ## github - 是個服務 - 可以上傳你的程式碼 ### 註冊gitub帳號 前往[官網](https://github.com) 註冊帳號 ![](https://i.imgur.com/E1fbdlO.png) ### 產生ssh key 並上傳到github 首先在終端機先輸入`cd`(到user那) -> `pwd`(確認是真的是user) 1. 先產生一個名為`.ssh`的資料夾,在終端機輸入`mkdir .ssh` 2. 前往該資料夾,`cd .ssh` 3. `ssh-keygen -t rsa -C "xxx@xxxxxx.com(自己的email)"`(產生自己的公鑰跟私鑰) ![](https://i.imgur.com/IgTisBG.png) 4. 輸入`cat id_rsa.pub`(cat公鑰,通常是把cat公鑰產生出來的碼貼到github上) ![](https://i.imgur.com/bxCB0JN.png) 5. 打開github -> setting -> ssh key 把公鑰貼過來並給他一個名字 ### github上創造一個Repository(repo) 1. 創造一個repo 點選上面的+,選擇new repository ![](https://i.imgur.com/TwcaZla.png) 2. 輸入你的repo的名稱,可以選擇將這個公開與否) ![](https://i.imgur.com/BTAMuTr.png) 3. 回到iterm - 要是本地電腦 **尚未有** 專案資料夾 選擇 `creat a new repository on the command line`操作 - 要是本地電腦**已有**專案資料夾 選擇 `push an existing repository from the command line`操作 - ![](https://i.imgur.com/gnfWP9l.png) ###### tags: `git`