Skip to content

Instantly share code, notes, and snippets.

@danmutblix
Forked from srebalaji/git-hard-delete
Created June 3, 2020 09:26
Show Gist options
  • Save danmutblix/efcfda58366423a91d230a953716ec51 to your computer and use it in GitHub Desktop.
Save danmutblix/efcfda58366423a91d230a953716ec51 to your computer and use it in GitHub Desktop.
Examples of git custom command
#!/bin/sh
branch=$1
if [ ! -z "$1" ]
then
git branch -D $branch
git push -d origin $branch
else
echo "Branch name is not specified"
fi
#!/bin/sh
message=$1 # First parameter will be the commit message
currentBranch=$(git symbolic-ref --short -q HEAD) # Getting the current branch
if [ ! -z "$1" ] # checking if the commit message is present. If not then aborting.
then
git add .
git commit -m "$message"
git push origin $currentBranch
else
echo "Commit message is not provided"
fi
#!/bin/sh
git fetch
remoteBranch=$(git symbolic-ref --short -q HEAD)
if [ ! -z "$1" ]
then
remoteBranch=$1
fi
echo "Showing diff between $remoteBranch origin/$remoteBranch"
git diff $remoteBranch origin/$remoteBranch
#!/bin/sh
git fetch
remoteBranch=$(git symbolic-ref --short -q HEAD)
if [ ! -z "$1" ]
then
remoteBranch=$1
fi
echo "Showing logs between $remoteBranch origin/$remoteBranch"
git log $remoteBranch..origin/$remoteBranch --oneline
#!/bin/sh
newBranch=$1
if [ ! -z "$1" ]
then
git stash
git checkout -b $newBranch
git stash pop
else
echo "Branch name is not specified"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment