Skip to main content

Branch

Tips
    branch-name 可使用斜線做分類識別,例如 test/feature1, dev/feature1
    Git branch
    # List all the branches
    git branch
    git branch -a
    
    # Create new branch
    git branch <branch-name>
    git checkout <branch-name>
    
    # Alternatively, using the following one-liner command
    # <origin-name> 為空白時,預設為目前 HEAD 版本, 例如 origin/main
    git checkout -b <branch-name> <origin-name>
    建立分支
    # Clone 專案
    git clone http://your.company.com/yourname/my_proj.git
    cd my_proj
    
    # 建立一個來源是 origin/main 的分支版,名稱為 test/util-cmd,並且切換(checkout)至分支版
    git checkout -b test/util-cmd origin/main
    git branch -a
    
    # Change your codes
    
    # 更新至本地專案庫
    git add .
    git commit -m "Added a new branch test/util-cmd"
    
    # 上傳至遠端專案庫
    git push --set-upstream origin test/util-cmd