简体   繁体   中英

Shortcut for deleting previous branch in git

In git it would be helpful to be able to easily delete the previous branch I was on. You can't delete the branch you're on so you need to check out a new/existing branch and delete the previous you where on by writing it's full name.

git checkout new_branch
git branch -D old_branch_with_really_long_and_hard_name

What I really want is to be able to do this:

git checkout new_branch
git branch -D -

- doesn't work, but - is just an alias for @{-1} and that does work. So you workflow would be this:

git checkout new_branch
git branch -D @{-1}

Amendment:

Turning this into the git alias git done :

git config --global alias.done '!f() { git checkout master && git branch -D @{-1}; }; f'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM