Skip to content

git cd should offer to stash/stash pop your changes when creating a new branch #112

@pchr-srf

Description

@pchr-srf

Currently, trying to start a new branch while having unstaged changes works like this:

$ git-cd start my-fancy-new-branch
git-cd start
Executing: git checkout main
D       some/file/i/deleted.js
M       some/modified/file.php
A       some/new/file.md
Your branch is up to date with 'origin/main'.
Executing: git pull origin main
Error: 
error: cannot pull with rebase: You have unstaged changes.
error: additionally, your index contains uncommitted changes.
error: please commit or stash them.

Ideally, it would work like this:

$ git-cd start my-fancy-new-branch
git-cd start
Checking if there are unstaged files...
Whoops, you got some unstaged files! Should I stash them and then re-apply them after [y/N]?
$ yes please, thank you
Executing: git stash
Executing: git checkout main
Executing: git pull origin main
Executing: git checkout -b my-fancy-new-branch
Executing: git push origin my-fancy-new-branch
Executing: git branch --set-upstream-to origin/my-fancy-new-branch
Executing: git stash pop

My current workaround is to enter git stash && git-cd start my-fancy-new-branch && git stash pop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions