Skip to content

Commit 5312b95

Browse files
authored
📝 git checkout/switching notes
1 parent 6c62602 commit 5312b95

File tree

1 file changed

+28
-2
lines changed
  • src/content/docs-md/random

1 file changed

+28
-2
lines changed

src/content/docs-md/random/git.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,38 @@ So this may look like so:
407407
git diff feature/stuff -- src/stuff/my-stuff.html
408408
```
409409

410-
# Checkout Previous Branch
410+
# Checkout/Switch Branches
411+
412+
> Checking out/switching are similar taks with `switch` being the "newer" way to do things
413+
414+
There are some alternative methods for checking out branches depending on what you want to do:
415+
416+
## Checkout/Switch from Current Branch
417+
418+
You can branch from your current branch with:
419+
420+
```sh
421+
git checkout -b feature/my-new-branch
422+
```
423+
424+
## Checkout/Switch from a Different Branch
425+
426+
Or you can checkout from another branch (e.g. `main`) without switching to it first, this can be done with:
427+
428+
```sh
429+
# you may want to update your local copy of `main` first
430+
git fetch origin main:main
431+
432+
# and then switch to it
433+
git switch -c feature/my-new-branch main
434+
```
435+
436+
# Checkout/Switch to Previous Branch
411437

412438
When switching branches, we can easily go to the last branch we were on using:
413439

414440
```sh
415-
git checkout -
441+
git switch -
416442
```
417443

418444
# Get Commit Changes from another Branch (Cherry Picking)

0 commit comments

Comments
 (0)