Skip to content

Instantly share code, notes, and snippets.

@dereckson
Last active August 25, 2021 22:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dereckson/6531b78ae526705276c56db5cf5b07b2 to your computer and use it in GitHub Desktop.
Save dereckson/6531b78ae526705276c56db5cf5b07b2 to your computer and use it in GitHub Desktop.
git-respawn
#!/bin/sh
if [ $# -ne 0 ]
then
>&2 echo "Usage: $(basename "$0")"
exit 1
fi
REPO_PATH=$(git rev-parse --show-toplevel)
REPO_RETCODE=$?
if [ $REPO_RETCODE -ne 0 ]
then
exit $REPO_RETCODE
fi;
REPO=$(basename "$REPO_PATH")
if [ -f $REPO_PATH/.git/arc/default-relative-commit ]
then
DEFAULT_BRANCH=$(awk -F / '{print $(NF)}' $REPO_PATH/.git/arc/default-relative-commit)
elif git show-ref --verify --quiet refs/heads/main
then
DEFAULT_BRANCH=main
else
DEFAULT_BRANCH=master
fi
echo $DEFAULT_BRANCH
#!/usr/bin/env bash
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
DEFAULT_BRANCH=$(git get-default-branch)
if [ "$CURRENT_BRANCH" = "$DEFAULT_BRANCH" ]; then
echo "You're on the default branch '$DEFAULT_BRANCH'. This feature is intended for feature branches."
exit 1
fi
# Updates master branch if there isn't any staged change and working tree is clean
git checkout "$DEFAULT_BRANCH"
git diff-index --quiet --cached HEAD -- && git diff-files --quiet && git pull
git branch -D "$CURRENT_BRANCH"
# Fetch new branch
if [ ${CURRENT_BRANCH:0:10} = "arcpatch-D" ]; then
arc patch ${CURRENT_BRANCH:9}
else
git fetch --all
git checkout "$CURRENT_BRANCH"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment