git shortcut—save to master and amend
May 15, 2020 ≈ 33 seconds
Sometimes you just want to save current work on master no matter on whatever branch you are in. And if you are on some branch—delete it, after saving everything to master. Here how I did it.
save() # save to master and amend
{
current_branch=$(git symbolic-ref --short HEAD)
if [ "$current_branch" = "master" ]; then
# if we are on master branch, save everything and return
git add .
git commit --amend --no-edit
return 0
fi
# otherwise, save everything from current branch to master
git stash
git checkout master
git stash pop
git add .
git commit --amend --no-edit
# and delete current branch
git branch -D $current_branch
}
You didn't provide any data, entered invalid email or already subscribed.
Try again. And if you still can't subscribe—write us.
Address successfully subscribed!
Subscribe to our newsletter
If you provide url of your website, we send you free design concept of one element (by our choice)
Subscribing to our newsletter, you comply with subscription terms and Privacy Policy