###### tags: `東京威力 TEL` # 02. basic application {%hackmd @925/Style %} ## <font color ="orange"> 02. GitHub -- application</font> :::spoiler git 概念圖 看這張圖會更好理解自己接下來在做什麼喔~  ::: ### <font color ="pink"> 2-1. create repo </font> 接下來我都會直接用 VSCode 去操作 Git(而不是在 Git Bash 中打指令)。 VSCode 幫我們把 Git 工具以按鍵代替指令,讓操作更快速方便、學習也更快。 我會把 vscode 中按鍵所對應的 「Git Bash 指令」寫出來。 一樣的步驟在 Git Bash 中打是一樣的效果。 #### <font color="yellow">step1. 到 vscode 中的 source control ,進行初始化。</font> > ``` > git init > ```  #### <font color="yellow">step2. 在 vscode 新增資料到暫存區 ( Storage Area )。</font> > ``` > git add . > ```  $\;\;\;\;\;\;$ #### <font color="yellow">step3. 寫 commit 訊息。</font> > ``` > git commit -m "first commit -- arduino project create" > ```  :::success **※ 第一次使用 git 會跳出的錯誤**  **解決方法如下:** 用快捷鍵 `ctrl + ~` 打開終端機,在右上方「+」的下拉選單中選 Git Bash。  這個必須在 Git Bash 中輸入以下兩行指令來告訴 Git 你是誰。 ```= git config --global user.name "MY_NAME" git config --global user.email "MY_EMAIL" ``` 指令的雙引號要留著。另外這個 email 和 name 都是指 GitHub 上的,不能亂取喔。 ::: #### <font color="yellow">step3. 按下「publish branch」建立分支。</font>  :::success **※ 第一次會有一些認證的步驟,點你直覺對的 ww**    ::: #### <font color="yellow">step4. 選擇 「publice repository」,並輸入「REPO_NAME」。</font> 截圖的範例名稱是 Python,但注意通常名稱是小寫開頭。 >``` >git remote add origin https:git@github.com:pomelo925/Python.git >git push -u origin master >```  (公開性之後也可以再到 Github 上去設定,選 public 可以讓其他人看看你的 repo。) :::info **幾個須要注意的事情:** 1. 為了方便我用 vscode 來操作 git。但很多技巧要靠打指令,所以建議大家找資料熟悉以指令來操作,對這些操作更熟悉再用 vscode 混搭也可以喔。 2. 遇錯時記得看 error message。複製貼上,網路上應該都能找到解方。 ::: ### <font color ="pink"> 2-2. git pull </font> #### <font color="yellow">step1. 到 Github 的 repo,在這裡新增 README。</font>  readme file 預設是 markdown 檔案,隨便寫寫即可。 ```md= # Python --- This is a sample for readme file. ``` #### <font color="yellow">step2. 到本地端的 vscode,進行 git pull。</font> > ``` > git pull -u origin master > ``` 到「source control」的右側「...」,選擇「提取」。  :::success **現在去看你的本地端資料,應該會多一個 readme 檔案喔!是不是很方便呢?** ::: ### <font color ="pink"> 2-3. git push </font> 上個小節是在雲端更改資料,而本地端 `git pull` 下來。 但通常是在本地端更改資料,而需要 `git push` 上去雲端的 remote repo 。 #### <font color="yellow">step1. 更改本地端資料,新增一個檔案 hello.txt。</font> ```= hello this is git push testing. ``` #### <font color="yellow">step2. git add 並 git commit。</font>  #### <font color="yellow">step3. sync change</font> ```= git push ``` 按下「同步變更」就能夠成功 push 上去囉!  :::success **現在去看 GitHub 的 repo,重新整理後應該會看到更新!** ::: :::info **※ 同步變更?** 假設今天在雲端新增 readme 後,我們沒有 git pull 下來;同時間我又在本地端新增了 hello.txt 檔案,這樣會出現本地和遠端版本不同的情況。 「同步變更」其實就是先「git pull」再「git push」,這樣可以避免發生上述狀況時有資料遺失。事實上,**git 規定了在 push 之前必須更新到和雲端版本相同**。必要時是可以透過 force 關鍵詞來強制推送,但你必須知道自己在做什麼。 ::: ### <font color ="pink"> 2-4. git clone </font> 假設我有了一台新裝置,想下載我放在 GitHub 上的 repo 時,要怎麼做呢? 那就是透過 `git clone` 指令下載,非常的簡單方便! #### <font color="yellow">step1. 複製 repo 的網址。</font> ```py= # 範例 git@github.com:pomelo925/tel2022_DoItTomorrow.git ```  #### <font color="yellow">step2. 到本地端任意資料夾位置開啟 git bash。</font> 進到資料夾內,點擊右鍵,選擇「Git Bash Here」。 (或是要用 vscode 開啟也可以。)  #### <font color="yellow">step3. git clone。</font> 輸入 `git clone` 指令並貼上網址。 ``` git clone git@github.com:pomelo925/tel2022_DoItTomorrow.git ```  檔案就成功下載下來囉,十分之方便 ~
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up