Skip to content

Offer to autostash changes when creating a new branch #3866

@brandondong

Description

@brandondong

Is your feature request related to a problem? Please describe.
Sometimes, I'm on branch A and then I want to create and switch to a new branch based off of branch B. So I navigate to the B branch in the branches panel and press n. However, if I have changed files, this can present the git error where I must commit or stash my changes first. It's often the case that lazygit's autostash feature would have saved me but the functionality is not present in this flow.

I don't see a reason why not. The action is basically the same as checking out B in terms of moving the HEAD pointer and the autostash feature is present there. Whenever I run into this, I just press <space> instead which triggers the autostash push and pop, and then press n.

Describe the solution you'd like
When creating a new branch and git returns the commit or stash error, offer to autostash.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Reproduction:

git init
echo -e "a\n\nb" > file
git add .
git commit -m "add file"
echo -e "a\n\nc" > file
git add .
git commit -m "edit last line"
git checkout -b dev HEAD~
echo -e "b\n\nb" > file
lazygit

Checking out the other branch (<space>) will work but trying to create and switch to a new branch based off of it (n) will not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions