ブランチ操作
ブランチを作成・切り替え・名前変更・削除して、変更を隔離した状態で作業します。
Working with branches in Git
A branch in Git is just a movable pointer to a commit, which is why creating one is instant and free. That cheapness shapes the whole workflow: you branch for every feature or fix, work in isolation, and merge back when it is ready. The commands here cover the full branch lifecycle - create, switch, rename, delete.
You will also find the modern split of git checkout into git switch (change branches) and git restore (restore files) covered on these pages, plus git worktree for the day you need two branches checked out at the same time without stashing anything.
よくある質問
How do I create a new branch and switch to it?
git switch -c feature-name creates the branch and moves you onto it in one step. The older git checkout -b feature-name does exactly the same thing and still works everywhere.What is the difference between git checkout and git switch?
git switch is the modern, branch-only half of git checkout: it changes branches and nothing else. git checkout also restores files and checks out commits, which made it easy to misuse - the split exists so each command does one thing.How do I delete a branch that is already merged?
git branch -d branch-name deletes it locally, and refuses if the branch has unmerged work (use -D to force). If it also exists on the remote, remove it there with git push origin --delete branch-name.