Skip to content

Commit 2cf8e7b

Browse files
authored
When checking out a remote branch by name, ask the user how (#3388)
- **PR Description** When checking out a remote branch by name, ask the user how they want to check it out; the choices are to create a new local branch that tracks the remote, or a detached head. This is an alternative to #3371, and fixes #2312.
2 parents 0360b82 + 6932e04 commit 2cf8e7b

File tree

15 files changed

+133
-13
lines changed

15 files changed

+133
-13
lines changed

docs/keybindings/Keybindings_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ If you would instead like to start an interactive rebase from the selected commi
263263
| Key | Action | Info |
264264
|-----|--------|-------------|
265265
| `` <c-o> `` | Copy branch name to clipboard | |
266-
| `` <space> `` | Checkout | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
266+
| `` <space> `` | Checkout | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
267267
| `` n `` | New branch | |
268268
| `` M `` | Merge | Merge selected branch into currently checked out branch. |
269269
| `` r `` | Rebase | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_ja.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ If you would instead like to start an interactive rebase from the selected commi
327327
| Key | Action | Info |
328328
|-----|--------|-------------|
329329
| `` <c-o> `` | ブランチ名をクリップボードにコピー | |
330-
| `` <space> `` | チェックアウト | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
330+
| `` <space> `` | チェックアウト | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
331331
| `` n `` | 新しいブランチを作成 | |
332332
| `` M `` | 現在のブランチにマージ | Merge selected branch into currently checked out branch. |
333333
| `` r `` | Rebase | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_ko.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ _Legend: `<c-b>` means ctrl+b, `<a-b>` means alt+b, `B` means shift+b_
240240
| Key | Action | Info |
241241
|-----|--------|-------------|
242242
| `` <c-o> `` | 브랜치명을 클립보드에 복사 | |
243-
| `` <space> `` | 체크아웃 | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
243+
| `` <space> `` | 체크아웃 | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
244244
| `` n `` | 새 브랜치 생성 | |
245245
| `` M `` | 현재 브랜치에 병합 | Merge selected branch into currently checked out branch. |
246246
| `` r `` | 체크아웃된 브랜치를 이 브랜치에 리베이스 | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_nl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ If you would instead like to start an interactive rebase from the selected commi
241241
| Key | Action | Info |
242242
|-----|--------|-------------|
243243
| `` <c-o> `` | Kopieer branch name naar klembord | |
244-
| `` <space> `` | Uitchecken | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
244+
| `` <space> `` | Uitchecken | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
245245
| `` n `` | Nieuwe branch | |
246246
| `` M `` | Merge in met huidige checked out branch | Merge selected branch into currently checked out branch. |
247247
| `` r `` | Rebase branch | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_pl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ If you would instead like to start an interactive rebase from the selected commi
240240
| Key | Action | Info |
241241
|-----|--------|-------------|
242242
| `` <c-o> `` | Copy branch name to clipboard | |
243-
| `` <space> `` | Przełącz | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
243+
| `` <space> `` | Przełącz | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
244244
| `` n `` | Nowa gałąź | |
245245
| `` M `` | Scal do obecnej gałęzi | Merge selected branch into currently checked out branch. |
246246
| `` r `` | Zmiana bazy gałęzi | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ If you would instead like to start an interactive rebase from the selected commi
297297
| Key | Action | Info |
298298
|-----|--------|-------------|
299299
| `` <c-o> `` | Скопировать название ветки в буфер обмена | |
300-
| `` <space> `` | Переключить | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
300+
| `` <space> `` | Переключить | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
301301
| `` n `` | Новая ветка | |
302302
| `` M `` | Слияние с текущей переключённой веткой | Merge selected branch into currently checked out branch. |
303303
| `` r `` | Перебазировать переключённую ветку на эту ветку | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ If you would instead like to start an interactive rebase from the selected commi
340340
| Key | Action | Info |
341341
|-----|--------|-------------|
342342
| `` <c-o> `` | 将分支名称复制到剪贴板 | |
343-
| `` <space> `` | 检出 | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
343+
| `` <space> `` | 检出 | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
344344
| `` n `` | 新分支 | |
345345
| `` M `` | 合并到当前检出的分支 | Merge selected branch into currently checked out branch. |
346346
| `` r `` | 将已检出的分支变基到该分支 | Rebase the checked-out branch onto the selected branch. |

docs/keybindings/Keybindings_zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ If you would instead like to start an interactive rebase from the selected commi
351351
| Key | Action | Info |
352352
|-----|--------|-------------|
353353
| `` <c-o> `` | 複製分支名稱到剪貼簿 | |
354-
| `` <space> `` | 檢出 | Checkout a new local branch based on the selected remote branch. The new branch will track the remote branch. |
354+
| `` <space> `` | 檢出 | Checkout a new local branch based on the selected remote branch, or the remote branch as a detached head. |
355355
| `` n `` | 新分支 | |
356356
| `` M `` | 合併到當前檢出的分支 | Merge selected branch into currently checked out branch. |
357357
| `` r `` | 將已檢出的分支變基至此分支 | Rebase the checked-out branch onto the selected branch. |

pkg/commands/git_commands/branch.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ func (self *BranchCommands) New(name string, base string) error {
2828
return self.cmd.New(cmdArgs).Run()
2929
}
3030

31+
// CreateWithUpstream creates a new branch with a given upstream, but without
32+
// checking it out
33+
func (self *BranchCommands) CreateWithUpstream(name string, upstream string) error {
34+
cmdArgs := NewGitCmd("branch").
35+
Arg("--track").
36+
Arg(name, upstream).
37+
ToArgv()
38+
39+
return self.cmd.New(cmdArgs).Run()
40+
}
41+
3142
// CurrentBranchInfo get the current branch information.
3243
func (self *BranchCommands) CurrentBranchInfo() (BranchInfo, error) {
3344
branchName, err := self.cmd.New(

pkg/gui/controllers/branches_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,10 @@ func (self *BranchesController) checkoutByName() error {
436436
FindSuggestionsFunc: self.c.Helpers().Suggestions.GetRefsSuggestionsFunc(),
437437
HandleConfirm: func(response string) error {
438438
self.c.LogAction("Checkout branch")
439+
_, branchName, found := self.c.Helpers().Refs.ParseRemoteBranchName(response)
440+
if found {
441+
return self.c.Helpers().Refs.CheckoutRemoteBranch(response, branchName)
442+
}
439443
return self.c.Helpers().Refs.CheckoutRef(response, types.CheckoutRefOptions{
440444
OnRefNotFound: func(ref string) error {
441445
return self.c.Confirm(types.ConfirmOpts{

0 commit comments

Comments
 (0)