Linux command
git-switch 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Switch to branch
git switch [branch]
Create and switch
git switch -c [new_branch]
Switch to previous branch
git switch -
Create from specific commit
git switch -c [branch] [commit]
Detach HEAD
git switch --detach [commit]
Force switch
git switch -f [branch]
Create orphan branch
git switch --orphan [branch]
说明
git switch changes the current branch. Introduced in Git 2.23 to provide a focused command for branch switching, separating this concern from `git checkout` which also handles file restoration. Use `-c` to create a new branch and switch to it in one step, or `--detach` to move to a specific commit without being on any branch.
参数
- -c, --create _branch_
- Create new branch.
- -C
- Create or reset branch.
- -d, --detach
- Detach HEAD.
- --orphan _branch_
- Create orphan branch.
- -f, --force
- Force switch.
- --guess
- Guess remote branch.
- --no-guess
- Don't guess remote.
- -t, --track
- Set up tracking.
FAQ
What is the git-switch command used for?
git switch changes the current branch. Introduced in Git 2.23 to provide a focused command for branch switching, separating this concern from `git checkout` which also handles file restoration. Use `-c` to create a new branch and switch to it in one step, or `--detach` to move to a specific commit without being on any branch.
How do I run a basic git-switch example?
Run `git switch [branch]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -c, --create _branch_ do in git-switch?
Create new branch.