Skip to main content


AndyBinOriginalAbout 1 min


view branch

git branch

create branch

git branch <name>

switch branch

git checkout <name>
git switch <name>
# switch is a new command in version 2.23

create and switch to this branch

git checkout -b <name>
git switch -c <name>

Merge the specified branch into the current branch

git merge <name>

delete local merged branch

git branch -d <name>

delete remote branch

git push <remote repository name> --delete <remote branch name>

Push the local branch to the remote repository and create a new branch in the remote repository

git push <remote repository name> <local branch name>:<remote branch name>


In the version WithdrawCommit section of the chapter BasicsKnowledge, you already know that for each commit, Git strings them together into a timeline, and this timeline is a branch. As of now, there is only one timeline. In Git, this branch is called the master branch, that is, the master branch. Strictly speaking, HEAD does not point to the commit, but to the master, and the master points to the commit, so HEAD points to the current branch.

Therefore, creating branches, switching branches, and deleting branches are only operations on the corresponding pointers, so the speed will be very fast.


We noticed that git checkout <branch> is used to switch branches, while the previously mentioned undo changes are git checkout -- <file>. The same command has two functions, which is indeed a bit confusing.

In fact, the action of switching branches is more scientific with switch. Therefore, the latest version of Git provides a new git switch command to switch branches. Using the new git switch command is easier to understand than git checkout.


git: 'switch' is not a git command
Because this command is released in version 2.23, there are no previous versions, you need to upgrade to the latest version

First, to view the current version, execute:

git --version

Before version 2.17.1, the upgrade command:

git update

After version 2.17.1, the upgrade command:

git update-git-for-windows
Last update:
Contributors: rumosky
  • Latest
  • Oldest
  • Hottest