###### tags: `程式組教程` # GitHub 教學(須改英文) ## 列出當前資料夾底下的所有檔案 ls ## 進到某資料夾 cd 資料夾名 ## 創建repo 首先在你要建立repo的地方右鍵打開 git bash 打git init ## 讓 git 追蹤某資料夾 git add 檔案名.txt(注意空格) git add .(將所有資料夾讓git追蹤) ## 保存當前進度 git commit -m "你修改了甚麼" ## 檢視歷史記錄 git log(他會顯示你剛剛-m""裡的東西) ## 檢視你現在所在的位置 git status ## 將資料夾上傳到github ### 在Github創repo ![](https://i.imgur.com/HE7zt3v.png) ![](https://i.imgur.com/WStRVeq.png) ![](https://i.imgur.com/Bc1YGNr.png) 複製這段後貼到你的gitBash (git remote add 自訂名稱 網址) ## 列出所有的remote git remote ## 將你的東西變成一個版本 git push origin(remote名稱) main(branch名稱) git push -u(將origin設成預設remote之後若不特別指定其他remote就會一律push到origin) origin(remote名稱) main(branch名稱) 第一次打這個之後就可以只打 git push ## 上傳檔案懶人包 1. git add . 2. git pull origin main 3. git commit -m "dick" 4. git push origin(remote名稱) main(branch名稱) ## 下載github上的檔案 1. cd repo 2. 先複製網址 ![](https://i.imgur.com/nzAX7Ul.png) 2. git clone 網址 3. git pull origin main 4. git add . ## 往前退一個commit git reset -- soft HEAD~1(只回到幾個commit之前) # Branch ## conflict two people revise the same code in the same repo and push it Simultaneously ### how to solve it ## Branch changing git checkout -- 分支名(之後push會跑到這) ### stash 在沒有push你現在修改的內容使用checkout時,修改內容會從原來的分支移動到切換後的分支。but 如果在切換後的分支中有相同檔案,但內容被修改過,checkout會失敗就要用到stash. ![](https://i.imgur.com/tV8zY61.png) ## HEAD 從當前分支往前x個版本(若在前面某版本中有另一個分支則也可以進入該分支)之後 如有push會push到HEAD過後的位置 git head ~number^number ![](https://i.imgur.com/dOUVmvs.png) ## 合併分支 ### merge ### rebase