branch 很輕,它只是指向 commit 的標籤
建立 branch 不會複製整個資料夾。git switch -c feature/login 會在目前 commit 建立新標籤,並讓 HEAD 改為指向它。
git branch
git switch -c feature/login
git add .
git commit -m "新增登入畫面"
git switch main
git merge feature/login
git branch -d feature/login
在 feature branch 建立 commit 時,只有該 branch 標籤向前;main 仍停在原處。這就是「不影響穩定主線」的核心。
git branch -d是安全刪除:若 branch 還有未合併 commit,Git 會拒絕。刪除 branch 標籤不代表立刻刪除已合併的 commit。
A branch is lightweight: it is only a label pointing to a commit
Creating a branch does not copy the entire folder. git switch -c feature/login adds a label at the current commit and points HEAD to it.
git branch
git switch -c feature/login
git add .
git commit -m "Add login screen"
git switch main
git merge feature/login
git branch -d feature/login
When you commit on the feature branch, only that label moves forward; main stays where it was. That is the core of working without disturbing the stable line.
git branch -dis the safe delete. Git refuses when unmerged commits remain. Deleting a branch label does not immediately delete an already merged commit.