Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

80%
+6 −0
Q&A How do I split a feature branch into two?

In the most general case[1] that you're asking about, you want the three-term rebase --onto. First, make your feature-2 branch: git switch --create feature-2 --A--B--C main \ ...

posted 6mo ago by Michael‭  ·  edited 6mo ago by Michael‭

Answer
#2: Post edited by user avatar Michael‭ · 2026-03-19T17:44:24Z (6 months ago)
Link the cherry pick answer. So good!
  • In the most general case[^cheats] that you're asking about, you want the three-term `rebase --onto`.
  • First, make your `feature-2` branch:
  • ```sh
  • git switch --create feature-2
  • ```
  • ```text
  • --A--B--C main
  • \
  • `Q--R--S--X--Y--Z feature-1, feature-2
  • ```
  • Next, move `feature-2`'s commits. Notice the `^` that I use to mark the *parent* of the last commit I want to move.
  • ```sh
  • git rebase --onto main feature-2 X^
  • ```
  • ```text
  • --A--B--C main
  • |\
  • | `Q--R--S--X--Y--Z feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • Finally, move `feature-1` back where it belongs:
  • ```sh
  • git switch feature-1
  • git reset --hard S
  • ```
  • ```text
  • --A--B--C main
  • |\
  • | `Q--R--S feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • The [Git rebase documentation][docs] for the three-term `--onto` starts in a position where `feature-1` is already where it needs to be.
  • For whatever reason, I'm much more likely to still be on `feature-1` and realize that I've started making a second feature. For that I'd rather use the `^` on the last commit I need to move rather than trace the lines of a `git log --graph` down to the parent commit.
  • [^cheats]: There are some tricks in simplified cases involving cherry picking instead of a rebase.
  • [docs]: https://git-scm.com/docs/git-rebase
  • In the most general case[^cheats] that you're asking about, you want the three-term `rebase --onto`.
  • First, make your `feature-2` branch:
  • ```sh
  • git switch --create feature-2
  • ```
  • ```text
  • --A--B--C main
  • \
  • `Q--R--S--X--Y--Z feature-1, feature-2
  • ```
  • Next, move `feature-2`'s commits. Notice the `^` that I use to mark the *parent* of the last commit I want to move.
  • ```sh
  • git rebase --onto main feature-2 X^
  • ```
  • ```text
  • --A--B--C main
  • |\
  • | `Q--R--S--X--Y--Z feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • Finally, move `feature-1` back where it belongs:
  • ```sh
  • git switch feature-1
  • git reset --hard S
  • ```
  • ```text
  • --A--B--C main
  • |\
  • | `Q--R--S feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • The [Git rebase documentation][docs] for the three-term `--onto` starts in a position where `feature-1` is already where it needs to be.
  • For whatever reason, I'm much more likely to still be on `feature-1` and realize that I've started making a second feature. For that I'd rather use the `^` on the last commit I need to move rather than trace the lines of a `git log --graph` down to the parent commit.
  • [^cheats]: There are some tricks in simplified cases involving cherry picking instead of a rebase. See [hkotsubo's excellent range cherry-pick answer](https://software.codidact.com/posts/295739/295751#answer-295751) for more.
  • [docs]: https://git-scm.com/docs/git-rebase
#1: Initial revision by user avatar Michael‭ · 2026-03-16T19:28:04Z (6 months ago)
In the most general case[^cheats] that you're asking about, you want the three-term `rebase --onto`.

First, make your `feature-2` branch:
```sh
git switch --create feature-2
```
```text
--A--B--C  main
         \
          `Q--R--S--X--Y--Z  feature-1, feature-2
```

Next, move `feature-2`'s commits. Notice the `^` that I use to mark the *parent* of the last commit I want to move.


```sh
git rebase --onto main feature-2 X^
```
```text
--A--B--C  main
        |\
        | `Q--R--S--X--Y--Z  feature-1
         \
          `X'-Y'-Z' feature-2
```

Finally, move `feature-1` back where it belongs:
```sh
git switch feature-1
git reset --hard S
```
```text
--A--B--C  main
        |\
        | `Q--R--S  feature-1
         \
          `X'-Y'-Z' feature-2
```

The [Git rebase documentation][docs] for the three-term `--onto` starts in a position where `feature-1` is already where it needs to be.

For whatever reason, I'm much more likely to still be on `feature-1` and realize that I've started making a second feature. For that I'd rather use the `^` on the last commit I need to move rather than trace the lines of a `git log --graph` down to the parent commit.

[^cheats]: There are some tricks in simplified cases involving cherry picking instead of a rebase.

[docs]: https://git-scm.com/docs/git-rebase