--- tags: Git, Github, 隨手筆記 --- # 隨手筆記 - Git語法及流程 ## 本文目的 學習git版本控制的操作 並且將專案送上github 方便多人協作專案 ## 流程說明 ### 初次使用 1. 建立倉庫(init) ### 每次開發階段 1. 將已修改過的檔案加入暫存區(add) 2. 提交修改(commit) ### 和別人協作 1. ### 開發新功能/重構/測試 1. 開分支 2. 合併/刪除分支 ## 基本設定 **設定username和email** ```shell git config --global user.name "<Your Name>" git config --global user.email "<your@gmail.com>" ``` ## 指令說明 **Init:** 在當下的目錄建立一個Repository ```shell git init ``` **Status** 顯示目前repository狀態 ```shell git status ``` **Add:** 將檔案或是目錄加到暫存區 ```shell git add <file_name/dir_name> ``` **Remove** 將檔案或是目錄從暫存區刪除 ```shell git rm --cached <file_name/dir_name> ``` **Commit:** 將暫存區的檔案提交出去 ```shell git commit -m "first commit" ``` **Branch:** * 新增 ```shell git branch <new_branch> ``` * 切換分支 ```shell git checkout <new_branch> ``` * 刪除分支 ```shell git branch <branch_name> -d git branch <branch_name> -D(強制) ``` * 更名分支 ```shell git branch <branch_name> -m git branch <branch_name> -M(強制) ``` * 合併分支 ```shell git checkout master git merge <new_branch> ``` **Remote** 連上遠端repository 以及將本機的commit push上遠端 ```shell git remote add origin git@github.com:<user>/<repository>.git git push -u origin master ``` 更改及查看origin來源 ```shell git remote set-url origin git@github.com:<user>/<repository>.git git remote -v ```
×
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