Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 -
like image 703
Pylinux Avatar asked Dec 10 '22 08:12

Pylinux


1 Answers

- 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'
like image 89
Pylinux Avatar answered Dec 22 '22 12:12

Pylinux