Add switch to branch
This commit is contained in:
22
snippets/create-branch.md
Normal file
22
snippets/create-branch.md
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
title: Create a new branch
|
||||
tags: branch,remote,beginner
|
||||
---
|
||||
|
||||
Creates and switches to a new branch, optionally setting up a remote tracking branch.
|
||||
|
||||
- Use `git checkout -b <branch>` to create a new branch with the specified name and switch to it.
|
||||
- You can optionally add `-t <remote>/<branch>` to set up a remote tracking branch for the newly created branch.
|
||||
- Note: You can alternatively use `git branch <branch> [-t <remote>/<branch>]` and then `git checkout <branch>` separately.
|
||||
|
||||
```sh
|
||||
git checkout -b <branch> [-t <remote>/<branch>]
|
||||
```
|
||||
|
||||
```sh
|
||||
git checkout -b patch-1
|
||||
# Local branch, without a remote tracking branch
|
||||
|
||||
git checkout -b patch-2 -t origin/patch-2
|
||||
# Local branch and remote tracking branch with the same name
|
||||
```
|
||||
17
snippets/switch-to-branch.md
Normal file
17
snippets/switch-to-branch.md
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
title: Switch to a branch
|
||||
tags: branch,beginner
|
||||
---
|
||||
|
||||
Switches to an existing branch.
|
||||
|
||||
- Use `git checkout <branch>` to switch to the specified branch.
|
||||
- Note: In newer versions of git, you can also use `git switch <branch>`.
|
||||
|
||||
```sh
|
||||
git checkout <branch>
|
||||
```
|
||||
|
||||
```sh
|
||||
git checkout patch-1 # Switches to the branch named `patch-1`
|
||||
```
|
||||
Reference in New Issue
Block a user