jesseduffield / lazygit

simple terminal UI for git commands
MIT License
52.65k stars 1.84k forks source link

Create a new branch without checkout. #3453

Closed yam-liu closed 5 months ago

yam-liu commented 7 months ago

Is your feature request related to a problem? Please describe. Yes, I use a backed branch for a top commit (some local config change) which should not be pushed to remote.

When I make some changes and amend the previous commit, I want to push the changes but not the top commit, I will use the backed branch (e.g. tmp) to track. delete the tmp and create a new branch at the top commit. But at this time, I don't want to checkout the branch, just for backing up.

Describe the solution you'd like create a branch without checkout or force create a same-name branch.

Describe alternatives you've considered push the branch from any commit of the branch, not only the top. something like git push origin the_branch~3:the_branch. I know I may lose some commit if do the operation, but a tip can be shown before the aciton.

Additional context .

stefanhaller commented 7 months ago

For creating a branch without checking it out, you could create a custom command similar to this one:

  - key: "<whatever>"
    description: 'Create a new branch without checking it out'
    command: "git branch {{index .PromptResponses 0}} {{.SelectedLocalCommit.Sha}}"
    context: 'commits'
    prompts:
      - type: 'input'
        title: 'Branch Name'
        initialValue: ''

For pushing a command that is not the head of your branch, a custom command like this one could be helpful.