mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Change The Start Point Of A Branch as a git til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_855 TILs and counting..._
|
_856 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -180,6 +180,7 @@ _855 TILs and counting..._
|
|||||||
- [Accessing a Lost Commit](git/accessing-a-lost-commit.md)
|
- [Accessing a Lost Commit](git/accessing-a-lost-commit.md)
|
||||||
- [Amend Author Of Previous Commit](git/amend-author-of-previous-commit.md)
|
- [Amend Author Of Previous Commit](git/amend-author-of-previous-commit.md)
|
||||||
- [Caching Credentials](git/caching-credentials.md)
|
- [Caching Credentials](git/caching-credentials.md)
|
||||||
|
- [Change The Start Point Of A Branch](git/change-the-start-point-of-a-branch.md)
|
||||||
- [Checking Commit Ancestry](git/checking-commit-ancestry.md)
|
- [Checking Commit Ancestry](git/checking-commit-ancestry.md)
|
||||||
- [Checkout Old Version Of A File](git/checkout-old-version-of-a-file.md)
|
- [Checkout Old Version Of A File](git/checkout-old-version-of-a-file.md)
|
||||||
- [Checkout Previous Branch](git/checkout-previous-branch.md)
|
- [Checkout Previous Branch](git/checkout-previous-branch.md)
|
||||||
|
|||||||
27
git/change-the-start-point-of-a-branch.md
Normal file
27
git/change-the-start-point-of-a-branch.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# Change The Start Point Of A Branch
|
||||||
|
|
||||||
|
More than a few times I have checked out a new branch against, say, `develop`
|
||||||
|
when I instead meant to base it off `qa`. I've tried what felt like the obvious
|
||||||
|
solution.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ git checkout qa
|
||||||
|
❯ git checkout -b new-branch
|
||||||
|
fatal: A branch named 'new-branch' already exists.
|
||||||
|
```
|
||||||
|
|
||||||
|
Git won't allow this. The fix I tend to go with is to delete the branch, move
|
||||||
|
to my intended starting point, and check it out anew.
|
||||||
|
|
||||||
|
Here is another approach. The `git checkout` command offers the `-B` flag which
|
||||||
|
will save me a step.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
❯ git checkout -B new-branch
|
||||||
|
Switched to and reset branch 'new-branch'
|
||||||
|
```
|
||||||
|
|
||||||
|
Use this with caution. Any commits that have been applied to the subject branch
|
||||||
|
will be reset (read: wiped out) in the process.
|
||||||
|
|
||||||
|
See `man git-checkout` for more details.
|
||||||
Reference in New Issue
Block a user