Created
March 8, 2021 22:27
-
-
Save mostlylikeable/9ef18dd21c325797e481ea976a82046c to your computer and use it in GitHub Desktop.
Pull down things created with git-migrate-up.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# git-migrate-down.sh | |
function _gm_not_dry_run() { | |
return 1 # set to 0 to run | |
} | |
# pulls all stashes down, re-stashes, and deletes local branch. | |
# - can uncomment line to also delete remote tmp stash branch | |
function pull_stashes() { | |
git fetch --all | |
local branches=() | |
while IFS= read -r line; do | |
branches+=$(echo $line | xargs) | |
done <<< "$(git branch -r --sort=committerdate | grep 'origin/stash_')" | |
for br in "${branches[@]}"; do | |
local short_name=$(basename $br) | |
_gm_status "syncing stash branch $br" | |
git checkout -b $short_name $br | |
git pull origin $short_name | |
local last_commit_msg=$(git log -1 --pretty=%s) | |
echo "creating stash with msg: $last_commit_msg" | |
git reset --soft HEAD~1 # undo last commit, which should be stashed | |
git stash save "$last_commit_msg" | |
git checkout main | |
# git push -d origin $short_name | |
git branch -d $short_name | |
done | |
} | |
function _gm_status() { | |
echo "\033[1;32m> $1\033[0m" | |
} | |
function _gm_status_dry() { | |
if _gm_not_dry_run; then | |
echo "" | |
else | |
echo "-- dry run (enable in _gm_dry_run)" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment