본문 바로가기
DevTools/Git

[Git] Switch Command

by llHoYall 2020. 10. 23.

This command helps to switch branches.

This command is experimental. (v2.29.0)

Description

Switch to a specified branch.

The working tree and the index are updated to match the branch.

Usage

Switch to Specified Branch

$ git switch <branch_name>

Create a New Branch and Switch to the Branch

$ git switch -c <new_branch_name>
$ git switch --create <new_branch_name>
$ git switch -c <new_branch_name> <start_branch_name>

Forced Switch to Specified Branch

Proceed even if the index or the working tree differs from HEAD.

Both the index and working tree are restored to match the switching target.

This is used to throw away local changes.

$ git switch -f <branch_name>
$ git switch --force <branch_name>
$ git switch --discard-changes <branch_name>

Create a New Branch with Setting Upstream

$ git switch -t <remote_branch_name>
$ git switch --track <remote_branch_name>
$ git switch --no-track <remote_branch_name>

Switch with Updating the Content of All Initialized SubModules

$ git switch --recurse-submodules <branch_name>
$ git switch --no-recurse-submodules <branch_name>

'DevTools > Git' 카테고리의 다른 글

[Git] Tip: Revert Merged Commit  (0) 2021.03.05
[Git] Tip: Change committer and author from already committed commit  (0) 2021.02.15
[Git] Restore Command  (0) 2020.10.23
[Git] Config Command  (0) 2020.09.23
[Git] Getting Started  (0) 2020.09.23

댓글