Skip to content

Instantly share code, notes, and snippets.

@benzap
Created June 19, 2015 14:25
Show Gist options
  • Save benzap/af13fe9990a53507091f to your computer and use it in GitHub Desktop.
Save benzap/af13fe9990a53507091f to your computer and use it in GitHub Desktop.
Useful shell commands for dealing with git
#!/bin/bash
#allows you to perform a rebase on your current branch with the master
#branch
#turn off the proxy
#. unsetproxy
CURRENT_BRANCH="`git rev-parse --abbrev-ref HEAD`"
echo "~~~ Current Branch: $CURRENT_BRANCH"
echo
echo "~~~ Switching to master..."
git checkout master
echo
echo "~~~ Pulling from master..."
git pull
echo
echo "~~~ Switching back to branch: $CURRENT_BRANCH"
git checkout $CURRENT_BRANCH
echo "~~~ Rebasing master..."
git rebase master
# Equivalent to this, but doesn't pull in origin/master > master
#git fetch origin
#git rebase origin/master
#!/bin/bash
# replaces the current remote branch with the current local
# branch. This is useful for situations where you wish to rebase your
# local branch again. Pushing the rebased branch when it already
# exists on the remote causes conflicts, which requires you to delete
# it before replacing it.
CURRENT_BRANCH="`git rev-parse --abbrev-ref HEAD`"
# Check if the current branch is master. Deleting this remotely would
# be a nightmare...
if [ $CURRENT_BRANCH = "master" ]
then
echo "~~~ ERROR: current branch is 'master,' this cannot be deleted remotely"
echo "~~~ Exiting..."
exit
else
echo "~~~ Current Branch: $CURRENT_BRANCH"
echo
fi
# Check if the remote branch for the current local branch exists
REMOTE_BRANCH="`git ls-remote --heads origin | grep $CURRENT_BRANCH`"
if [ -n "$REMOTE_BRANCH" ]
then
echo "~~~ Remote Branch Exists: $REMOTE_BRANCH"
echo "~~~ Deleting remote branch: $CURRENT_BRANCH"
git push origin :$CURRENT_BRANCH
echo
echo "~~~ Pushing new remote branch"
git push origin $CURRENT_BRANCH
else
echo "~~~ No remote branch present for '$CURRENT_BRANCH'"
echo "~~~ No Action Taken"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment