# 基本git指令 首先我們要先建立一個local repository ``` git init ``` ![](https://i.imgur.com/1sZr9F3.png) ## 新增一個GIT記事 假設我們剛剛寫了一個簡單的hello.c 程式,我們現在要把他用新增到working stage 中,並且新增一個commit (快照) ``` git add <file_name> ``` ``` git commit -m <file_name> ``` 然後我們移動到newbranch (如果沒有就會自己新增一個branch 叫做newbranch)上 ``` git branch -M <branch_name> ``` ![](https://i.imgur.com/uiAmZXK.png) ## 將整個local repository推到github上面 在將我們的local repository 推到Github 上之前,我們要先新增目的地址。然後再將我們整個local repository推上去。這樣Github 就會記錄我們剛剛做了哪些事。 ``` git remote add <remote_name> git@<github_repository_address> ``` ``` git push -u <remote_name> <branch_name> ``` 從以下的圖片我們可以看到Github 顯示了我們剛剛推上去的local repository。 ![](https://i.imgur.com/4sYsEpQ.png) ![](https://i.imgur.com/RWvEN65.png) ![](https://i.imgur.com/PsXwtzc.png) ## GIT具體使用 如果我們對hello.c 做出了改變。我們就可以用一樣的步驟再重新把他記錄起來,並且推到Github 上。此時我們可以看到Github 上新增了新的commit 且記錄了我們做出了什麼樣的改變。 ![](https://i.imgur.com/JfFJ5UO.png) ![](https://i.imgur.com/AQDPQru.png) ![](https://i.imgur.com/3RFOl4i.png) 這就大概是Git 與Github 的基本用法與概念。