Skip to content

Instantly share code, notes, and snippets.

@mishak87
Last active August 29, 2015 14:14
Show Gist options
  • Save mishak87/c163939b6980689d7a05 to your computer and use it in GitHub Desktop.
Save mishak87/c163939b6980689d7a05 to your computer and use it in GitHub Desktop.
Git tool scripts
#!/bin/bash
# Safest push default behaviour
git config --global push.default simple
# Reseting permissions (file mode) http://stackoverflow.com/a/4408378/1765978
git config --global --add alias.permission-reset '!git diff -p -R | grep -E "^(diff|(old|new) mode)" | git apply'
git permission-reset
# Global .gitignore file in home directory
git config --global core.excludesfile '~/.gitignore'
#!/bin/bash
TMP=$(git symbolic-ref HEAD 2>/dev/null)
BRANCH=${TMP##refs/heads/}
if [ -z "$BRANCH" ]; then
echo "You are detached"
exit 1
fi
TMP=$(git for-each-ref --format='%(upstream:short)' "refs/heads/$BRANCH")
REMOTE=${TMP%%/*}
REMOTE_BRANCH=${TMP#*/}
if [ -z "$REMOTE" ]; then
echo "Branch $BRANCH is not tracked at remote $REMOTE, try:"
echo "git push $REMOTE -u $BRANCH"
exit 1
fi
echo "Removing $BRANCH from $REMOTE"
git push "$REMOTE" ":$REMOTE_BRANCH"
echo "Pushing $BRANCH branch to $REMOTE"
git push "$REMOTE" -u "$REMOTE_BRANCH"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment