Last active
October 10, 2023 13:10
-
-
Save srebalaji/4b23fb62f6ce26c17b73ca07ae7cfc67 to your computer and use it in GitHub Desktop.
Examples of git custom command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
I update the script to take into account existing local branches, and also updated to replace
git checkout
with git switch as that is the current standard.