# Git 實用筆記 [TOC] ## 如何設定遠端repo位址: 參考 [設定遠端url](https://gist.github.com/fokayx/255b228ded2bca1c4f60) * 1.確認目前Git遠端伺服器網址: git remote -v ```git git remote -v ``` 回傳結果: ```git= origin https://github.com/USERNAME/REPOSITORY.git (fetch) origin https://github.com/USERNAME/REPOSITORY.git (push) ``` * 2.更換Git遠端伺服器位網址,使用:git remote set-url ```git git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git ``` * 3.再次確認Git遠端伺服器網址 ```git git remote -v ``` ```git= origin https://github.com/USERNAME/OTHERREPOSITORY.git (fetch) origin https://github.com/USERNAME/OTHERREPOSITORY.git (push) ``` * 如果是使用SSH的存取網址,指令一樣是使用git remote set-url,再接上新的SSH URL就可以更換,指令如下: ```git git remote set-url origin git@github.com:USERNAME/OTHERREPOSITORY.git ``` * 不管是要HTTP/HTTPS跟SSH,二種存取網址都是可以直接做更換,然後下次git push/ git fetch 就會到新設定的網址去了唷。 --- ## 1. 從 GitLab 或 GitHub上 **git clone https://...** 後,可以在local 端資料夾使用以下幾個好用指令**確認自己在哪個branch**,才不會出現找不到你已經更改的內容而恐慌。 ```git= git status ``` * 確認自己正在 **哪條branch**上 ```git= git checkout [branch_name] ``` * 切換到自己要的那條branch ```git= git branch [branch_name] ``` * 建立一條新的branch ```git= git checkout -b [branch_name] ``` * 建立一條新branch同時**切換到該branch上** ```git= git branch ``` * 看總共有幾個branch ## 2. 當你編輯完新的檔案,要 Push 上 repo 時... ```git= git add * ``` * 加入所有改變 ```git= git commit -m "What you've done" ``` * 描述此次 push 你改變了甚麼 ```git= git push origin [branch_name] ``` * 此步驟很重要!!如果只有打 `git push`很可能洗到其他分支(master),非常危險 (會被組員打死XD) ###### tags: `Git`