Shell使用git
在github上面建立一個新的專案,命名為GitTest
github: https://github.com/linx214/GitTest.git
1. 建立Github倉庫
開啟terminal,建立本地github倉庫
git clone https://github.com/linx214/GitTest.git
上傳README.me檔案到github倉庫
cd GitTest echo "# GitTest" >> README.md git add README.md git commit -m "提交README.md檔案" git push -u origin master
編寫一個main.cpp檔案,編輯內容並上傳到github上
touch main.cpp open main.cpp 編輯內容 #include <iostream> int main(int argc, char* argv[]) { std::cout << "Hello, World!" << std::endl; return 0; } git add main.cpp git commit -m "提交main.cpp檔案" git push -u origin master
當main.cpp發生變更時,使用git status檢視本地變動位置

image.png
使用git add *, 新增全部本地改動
git add *

image.png
如需將改動提交至github上,使用git commit -m "註釋", git push -u origin master 即可
2. 分支 branch
2.1 檢視當前分支
git branch -a

image.png
2.2 切換分支
git checkout dev

image.png
2.3 在分支上進行提交動作
git checkout test #切換到test分支 #程式碼變更 git add * git commit -m "在test分支上進行提交變更" git push origin test