Skip to content

Commit aa68885

Browse files
authored
Add new command "Move commits to new branch" (#3876)
- **PR Description** Add a new command "Move commits to new branch" (bound to `N` by default), which is useful if you have just started some new work, you already made some commits, and then you realize that you forgot to create a new branch first, accidentally making those commits on main or whichever other feature branch you happened to be on. If you made those commits on main, you are prompted for a branch name for the new branch, and then it creates the new branch right there and hard-resets main to where it was. If you made them on another feature branch though, you are first given the choice whether you want to create the new branch from main, or keep it stacked on that other feature branch. Then it prompts you for the name and proceeds as above. Inspired by Magit's [magit-branch-spinoff](https://magit.vc/manual/magit/Branch-Commands.html#index-b-s) command. The conditions under which the command is available are rather restrictive: the current branch must have an upstream, it must not be behind its upstream, but it must be ahead of it (otherwise there wouldn't be any commits to move, and you might as well just create a new branch normally).
2 parents bd1e34b + f65166a commit aa68885

24 files changed

+558
-26
lines changed

docs/Config.md

+1
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ keybinding:
587587
rebaseBranch: r
588588
renameBranch: R
589589
mergeIntoCurrentBranch: M
590+
moveCommitsToNewBranch: "N"
590591
viewGitFlowOptions: i
591592
fastForward: f
592593
createTag: T

docs/keybindings/Keybindings_en.md

+12
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ If you would instead like to start an interactive rebase from the selected commi
109109
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
110110
| `` o `` | Open commit in browser | |
111111
| `` n `` | Create new branch off of commit | |
112+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
113+
114+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
112115
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
113116
| `` C `` | Copy (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
114117
| `` <c-t> `` | Open external diff tool (git difftool) | |
@@ -166,6 +169,9 @@ If you would instead like to start an interactive rebase from the selected commi
166169
| `` i `` | Show git-flow options | |
167170
| `` <space> `` | Checkout | Checkout selected item. |
168171
| `` n `` | New branch | |
172+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
173+
174+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
169175
| `` o `` | Create pull request | |
170176
| `` O `` | View create pull request options | |
171177
| `` <c-y> `` | Copy pull request URL to clipboard | |
@@ -266,6 +272,9 @@ If you would instead like to start an interactive rebase from the selected commi
266272
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
267273
| `` o `` | Open commit in browser | |
268274
| `` n `` | Create new branch off of commit | |
275+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
276+
277+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
269278
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
270279
| `` C `` | Copy (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
271280
| `` <c-r> `` | Reset copied (cherry-picked) commits selection | |
@@ -347,6 +356,9 @@ If you would instead like to start an interactive rebase from the selected commi
347356
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
348357
| `` o `` | Open commit in browser | |
349358
| `` n `` | Create new branch off of commit | |
359+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
360+
361+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
350362
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
351363
| `` C `` | Copy (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
352364
| `` <c-r> `` | Reset copied (cherry-picked) commits selection | |

docs/keybindings/Keybindings_ja.md

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
8282
| `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
8383
| `` o `` | ブラウザでコミットを開く | |
8484
| `` n `` | コミットにブランチを作成 | |
85+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
86+
87+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
8588
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
8689
| `` C `` | コミットをコピー (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
8790
| `` <c-r> `` | Reset copied (cherry-picked) commits selection | |
@@ -133,6 +136,9 @@ If you would instead like to start an interactive rebase from the selected commi
133136
| `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
134137
| `` o `` | ブラウザでコミットを開く | |
135138
| `` n `` | コミットにブランチを作成 | |
139+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
140+
141+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
136142
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
137143
| `` C `` | コミットをコピー (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
138144
| `` <c-t> `` | Open external diff tool (git difftool) | |
@@ -250,6 +256,9 @@ If you would instead like to start an interactive rebase from the selected commi
250256
| `` i `` | Show git-flow options | |
251257
| `` <space> `` | チェックアウト | Checkout selected item. |
252258
| `` n `` | 新しいブランチを作成 | |
259+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
260+
261+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
253262
| `` o `` | Pull Requestを作成 | |
254263
| `` O `` | View create pull request options | |
255264
| `` <c-y> `` | Pull RequestのURLをクリップボードにコピー | |
@@ -380,6 +389,9 @@ If you would instead like to start an interactive rebase from the selected commi
380389
| `` y `` | コミットの情報をコピー | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
381390
| `` o `` | ブラウザでコミットを開く | |
382391
| `` n `` | コミットにブランチを作成 | |
392+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
393+
394+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
383395
| `` g `` | Reset | View reset options (soft/mixed/hard) for resetting onto selected item. |
384396
| `` C `` | コミットをコピー (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
385397
| `` <c-r> `` | Reset copied (cherry-picked) commits selection | |

docs/keybindings/Keybindings_ko.md

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
6060
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
6161
| `` o `` | 브라우저에서 커밋 열기 | |
6262
| `` n `` | 커밋에서 새 브랜치를 만듭니다. | |
63+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
64+
65+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
6366
| `` g `` | View reset options | View reset options (soft/mixed/hard) for resetting onto selected item. |
6467
| `` C `` | 커밋을 복사 (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
6568
| `` <c-r> `` | Reset cherry-picked (copied) commits selection | |
@@ -101,6 +104,9 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
101104
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
102105
| `` o `` | 브라우저에서 커밋 열기 | |
103106
| `` n `` | 커밋에서 새 브랜치를 만듭니다. | |
107+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
108+
109+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
104110
| `` g `` | View reset options | View reset options (soft/mixed/hard) for resetting onto selected item. |
105111
| `` C `` | 커밋을 복사 (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
106112
| `` <c-r> `` | Reset cherry-picked (copied) commits selection | |
@@ -200,6 +206,9 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
200206
| `` i `` | Git-flow 옵션 보기 | |
201207
| `` <space> `` | 체크아웃 | Checkout selected item. |
202208
| `` n `` | 새 브랜치 생성 | |
209+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
210+
211+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
203212
| `` o `` | 풀 리퀘스트 생성 | |
204213
| `` O `` | 풀 리퀘스트 생성 옵션 | |
205214
| `` <c-y> `` | 풀 리퀘스트 URL을 클립보드에 복사 | |
@@ -305,6 +314,9 @@ If you would instead like to start an interactive rebase from the selected commi
305314
| `` y `` | 커밋 attribute 복사 | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
306315
| `` o `` | 브라우저에서 커밋 열기 | |
307316
| `` n `` | 커밋에서 새 브랜치를 만듭니다. | |
317+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
318+
319+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
308320
| `` g `` | View reset options | View reset options (soft/mixed/hard) for resetting onto selected item. |
309321
| `` C `` | 커밋을 복사 (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
310322
| `` <c-t> `` | Open external diff tool (git difftool) | |

docs/keybindings/Keybindings_nl.md

+12
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
9999
| `` i `` | Laat git-flow opties zien | |
100100
| `` <space> `` | Uitchecken | Checkout selected item. |
101101
| `` n `` | Nieuwe branch | |
102+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
103+
104+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
102105
| `` o `` | Maak een pull-request | |
103106
| `` O `` | Bekijk opties voor pull-aanvraag | |
104107
| `` <c-y> `` | Kopieer de URL van het pull-verzoek naar het klembord | |
@@ -177,6 +180,9 @@ If you would instead like to start an interactive rebase from the selected commi
177180
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
178181
| `` o `` | Open commit in browser | |
179182
| `` n `` | Creëer nieuwe branch van commit | |
183+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
184+
185+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
180186
| `` g `` | Bekijk reset opties | View reset options (soft/mixed/hard) for resetting onto selected item. |
181187
| `` C `` | Kopieer commit (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
182188
| `` <c-t> `` | Open external diff tool (git difftool) | |
@@ -244,6 +250,9 @@ If you would instead like to start an interactive rebase from the selected commi
244250
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
245251
| `` o `` | Open commit in browser | |
246252
| `` n `` | Creëer nieuwe branch van commit | |
253+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
254+
255+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
247256
| `` g `` | Bekijk reset opties | View reset options (soft/mixed/hard) for resetting onto selected item. |
248257
| `` C `` | Kopieer commit (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
249258
| `` <c-r> `` | Reset cherry-picked (gekopieerde) commits selectie | |
@@ -347,6 +356,9 @@ If you would instead like to start an interactive rebase from the selected commi
347356
| `` y `` | Copy commit attribute to clipboard | Copy commit attribute to clipboard (e.g. hash, URL, diff, message, author). |
348357
| `` o `` | Open commit in browser | |
349358
| `` n `` | Creëer nieuwe branch van commit | |
359+
| `` N `` | Move commits to new branch | Create a new branch and move the unpushed commits of the current branch to it. Useful if you meant to start new work and forgot to create a new branch first.
360+
361+
Note that this disregards the selection, the new branch is always created either from the main branch or stacked on top of the current branch (you get to choose which). |
350362
| `` g `` | Bekijk reset opties | View reset options (soft/mixed/hard) for resetting onto selected item. |
351363
| `` C `` | Kopieer commit (cherry-pick) | Mark commit as copied. Then, within the local commits view, you can press `V` to paste (cherry-pick) the copied commit(s) into your checked out branch. At any time you can press `<esc>` to cancel the selection. |
352364
| `` <c-r> `` | Reset cherry-picked (gekopieerde) commits selectie | |

0 commit comments

Comments
 (0)