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

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

The rebase solution proposed in the other answer is the most straightforward way (and the one I'd use as well). Just to provide an alternative, you can also use cherry-pick. First, let's create b...

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

Answer
#2: Post edited by user avatar hkotsubo‭ · 2026-03-17T19:13:27Z (6 months ago)
  • The `rebase` solution proposed in the [other answer](/posts/295739/295740#answer-295740) is the most straightforward way (and the one I'd use as well).
  • Just to provide an alternative, you can also use [`cherry-pick`](https://git-scm.com/docs/git-cherry-pick).
  • First, let's create branch feature-2 from main, and switch to it:
  • ```bash
  • git switch --create feature-2 main
  • ```
  • Now we have:
  • ```none
  • --A--B--C main, feature-2 (HEAD)
  • \
  • `Q--R--S--X--Y--Z feature-1
  • ```
  • And feature-2 is the current branch. Then we cherry-pick all commits from X to Z:
  • ```bash
  • git cherry-pick X^..Z
  • ```
  • Obviously, replacing X and Z by their respective hashes. Note that after X there's a `^`, so `X^..Z` corresponds to all commits reachable from Z but not reachable from X's parent (in this case, it's X, Y and Z).
  • This will apply commits X, Y and Z to feature-2, resulting in:
  • ```none
  • --A--B--C main
  • |\
  • | `Q--R--S--X--Y--Z feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • Finally, we just move feature-1 to S (this part is the same as the other answer):
  • ```bash
  • git switch feature-1
  • git reset --hard S
  • ```
  • ```none
  • --A--B--C main
  • |\
  • | `Q--R--S feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • ---
  • Alternatively, you can also list the commits one by one, like `git cherry-pick X Y Z`. But if there are too many commits, this can be tedious and very error-prone, and the two-dots syntax is a better solution.
  • ---
  • As I said, using rebase is more straightforward, I'd just wanted to show an alternative. After all, [you can think of rebase as a faster way to cherry-pick a specific set of commits](https://think-like-a-git.net/sections/rebase-from-the-ground-up/using-git-cherry-pick-to-simulate-git-rebase.html).
  • The `rebase` solution proposed in the [other answer](/posts/295739/295740#answer-295740) is the most straightforward way (and the one I'd use as well).
  • Just to provide an alternative, you can also use [`cherry-pick`](https://git-scm.com/docs/git-cherry-pick).
  • First, let's create branch `feature-2` from `main`, and switch to it:
  • ```bash
  • git switch --create feature-2 main
  • ```
  • Now we have:
  • ```none
  • --A--B--C main, feature-2 (HEAD)
  • \
  • `Q--R--S--X--Y--Z feature-1
  • ```
  • And `feature-2` is the current branch. Then we `cherry-pick` all commits from X to Z:
  • ```bash
  • git cherry-pick X^..Z
  • ```
  • Obviously, replacing X and Z by their respective hashes. Note that after X there's a `^`, so `X^..Z` corresponds to all commits reachable from Z but not reachable from X's parent (in this case, it'll be commits X, Y and Z).
  • This will apply commits X, Y and Z to `feature-2`, resulting in:
  • ```none
  • --A--B--C main
  • |\
  • | `Q--R--S--X--Y--Z feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • Finally, we just move `feature-1` to S (this part is the same as the other answer):
  • ```bash
  • git switch feature-1
  • git reset --hard S
  • ```
  • And the repository will look like this:
  • ```none
  • --A--B--C main
  • |\
  • | `Q--R--S feature-1
  • \
  • `X'-Y'-Z' feature-2
  • ```
  • ---
  • Alternatively, you can also list the commits one by one, like `git cherry-pick X Y Z`. But if there are too many commits, this can be tedious and very error-prone, and the two-dots syntax is a better solution.
  • ---
  • As I said, using `rebase` is more straightforward, I'd just wanted to show an alternative. After all, [you can think of `rebase` as a faster way to `cherry-pick` a specific set of commits](https://think-like-a-git.net/sections/rebase-from-the-ground-up/using-git-cherry-pick-to-simulate-git-rebase.html).
#1: Initial revision by user avatar hkotsubo‭ · 2026-03-17T11:09:17Z (6 months ago)
The `rebase` solution proposed in the [other answer](/posts/295739/295740#answer-295740) is the most straightforward way (and the one I'd use as well).

Just to provide an alternative, you can also use [`cherry-pick`](https://git-scm.com/docs/git-cherry-pick).

First, let's create branch feature-2 from main, and switch to it:

```bash
git switch --create feature-2 main
```

Now we have:

```none
--A--B--C  main, feature-2 (HEAD)
         \
          `Q--R--S--X--Y--Z  feature-1
```

And feature-2 is the current branch. Then we cherry-pick all commits from X to Z:

```bash
git cherry-pick X^..Z
```

Obviously, replacing X and Z by their respective hashes. Note that after X there's a `^`, so `X^..Z` corresponds to all commits reachable from Z but not reachable from X's parent (in this case, it's X, Y and Z).

This will apply commits X, Y and Z to feature-2, resulting in:

```none
--A--B--C  main
        |\
        | `Q--R--S--X--Y--Z  feature-1
         \
          `X'-Y'-Z' feature-2
```

Finally, we just move feature-1 to S (this part is the same as the other answer):

```bash
git switch feature-1
git reset --hard S
```

```none
--A--B--C  main
        |\
        | `Q--R--S  feature-1
         \
          `X'-Y'-Z' feature-2
```


---

Alternatively, you can also list the commits one by one, like `git cherry-pick X Y Z`. But if there are too many commits, this can be tedious and very error-prone, and the two-dots syntax is a better solution.

---

As I said, using rebase is more straightforward, I'd just wanted to show an alternative. After all, [you can think of rebase as a faster way to cherry-pick a specific set of commits](https://think-like-a-git.net/sections/rebase-from-the-ground-up/using-git-cherry-pick-to-simulate-git-rebase.html).