Skip to content

Instantly share code, notes, and snippets.

@adilsoncarvalho
Last active March 20, 2018 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adilsoncarvalho/251937d39d07436a65ac356657d9e8d8 to your computer and use it in GitHub Desktop.
Save adilsoncarvalho/251937d39d07436a65ac356657d9e8d8 to your computer and use it in GitHub Desktop.
Goes back to master while pulling from origin and removing the local branches deleted on origin

git-extensions

This small piece of code just adds the gl! function to the official git zshell plugin. It switches to the master branch an pulls changes from the remote, removing locally all branches that got deleted on remote.

NOTE: consider the potential issues of deleting your local branches (aka use at your own risk)

How to use

gl!

What it does

Basically it runs the following commands:

git checkout master
git pull --prune --all

# for each branch marked as [deleted] it'll run
git branch -D BRANCH_NAME

How to install

curl --location https://bit.ly/git-extra > $ZSH/custom/git-extra.plugin.zsh
function gl!() {
gco master || return 1;
OUTPUT=$(git pull --prune --all)
SELECTED=$(grep "\[deleted\]" <<< $OUTPUT)
DELETABLE=$(echo $SELECTED | sed -E "s|^.*origin/||g")
echo $OUTPUT
if [ -z $DELETABLE ]; then
echo "-> 🎉 There are no branches to remove"
else
echo "-> The following branches will be removed:"
echo $DELETABLE
for BRANCH in $DELETABLE; do
git branch -D $BRANCH
done;
echo "-> 🌪 They're gone"
fi
}
MIT License
Copyright (c) 2018 Adilson Luiz Carvalho
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment