Skip to content

Instantly share code, notes, and snippets.

@telmotrooper
Last active October 17, 2020 01:33
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 telmotrooper/2facfb5ab33fb501ce256f3ba3552f62 to your computer and use it in GitHub Desktop.
Save telmotrooper/2facfb5ab33fb501ce256f3ba3552f62 to your computer and use it in GitHub Desktop.
POSIX-compliant commands to automate common Git tasks
# Create a new branch based on the current one and push it to the remote.
function gcob {
echo "You're on branch \"$(git branch --show-current)\"."
git pull
echo "Creating branch with name \"$1\"."
git checkout -b $1
echo "Pushing branch to remote."
git push --set-upstream origin $1
}
# Delete a branch both on local and remote.
function gdel {
echo "Deleting branch \"$1\" both locally and remotely is a destructive operation."
echo -n "Do you want to proceed anyway? (y/N) "
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
git branch -d $1 & git push origin --delete $1
echo "Branch \"$1\" deleted."
else
echo "Operation aborted."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment