Skip to content

Instantly share code, notes, and snippets.

@anzz1
Created June 15, 2023 05:35
Show Gist options
  • Save anzz1/25aba9832ceb7ce9f8a456a56bd62737 to your computer and use it in GitHub Desktop.
Save anzz1/25aba9832ceb7ce9f8a456a56bd62737 to your computer and use it in GitHub Desktop.
GitHub git shorthands
#!/bin/sh
ghcommit() {
git config user.name "**USERNAME**" && \
git config user.email "**EMAIL**" && \
echo git commit && \
git commit
}
ghclone-s() {
if [ ! -z "$1" ]; then
echo git clone --depth=1 "https://github.com/"$1".git"
git clone --depth=1 "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-sb() {
if [ ! -z "$1" ] && [ ! -z "$2" ]; then
echo git clone --depth=1 -b "$2" --single-branch "https://github.com/"$1".git"
git clone --depth=1 -b "$2" --single-branch "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-sr() {
if [ ! -z "$1" ]; then
echo git clone --depth=1 --recurse-submodules --shallow-submodules "https://github.com/"$1".git"
git clone --depth=1 --recurse-submodules --shallow-submodules "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-srb() {
if [ ! -z "$1" ] && [ ! -z "$2" ]; then
echo git clone --depth=1 --recurse-submodules --shallow-submodules -b "$2" --single-branch "https://github.com/"$1".git"
git clone --depth=1 --recurse-submodules --shallow-submodules -b "$2" --single-branch "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-r() {
if [ ! -z "$1" ]; then
echo git clone --recurse-submodules "https://github.com/"$1".git"
git clone --recurse-submodules "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-b() {
if [ ! -z "$1" ] && [ ! -z "$2" ]; then
echo git clone -b "$2" --single-branch "https://github.com/"$1".git"
git clone -b "$2" --single-branch "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-rb() {
if [ ! -z "$1" ] && [ ! -z "$2" ]; then
echo git clone --recurse-submodules -b "$2" --single-branch "https://github.com/"$1".git"
git clone --recurse-submodules -b "$2" --single-branch "https://github.com/"$1".git"
else
ghclone
fi
}
ghclone-br() {
ghclone-rb "$@"
}
ghclone-rs() {
ghclone-sr "$@"
}
ghclone-bs() {
ghclone-sb "$@"
}
ghclone-sbr() {
ghclone-srb "$@"
}
ghclone-bsr() {
ghclone-srb "$@"
}
ghclone-rsb() {
ghclone-srb "$@"
}
ghclone-brs() {
ghclone-srb "$@"
}
ghclone-rbs() {
ghclone-srb "$@"
}
ghclone() {
if [ -z "$1" ]; then
echo "clone repo? \`ghclone user/repo\`"
echo "clone repo (recurse)? \`ghclone-r user/repo\`"
echo "clone repo (shallow)? \`ghclone-s user/repo\`"
echo "clone repo (branch)? \`ghclone-b user/repo branch\`"
return
fi
echo git clone "https://github.com/"$1".git"
git clone "https://github.com/"$1".git"
}
ghpush() {
var1="$(git config --get remote.origin.url)"
if ! ((echo "$var1" | grep -c "https://github.com/**USERNAME**/") &> /dev/null); then
echo "bad repo url: \""$var1"\""
return
fi
var2="$(basename "$var1")"
if [ -z "$var2" ]; then
echo "repo name empty!"
return
fi
if [ -z "$1" ]; then
echo "repo: \"https://github.com/**USERNAME**/"$var2"\""
echo "push all? \`ghpush !\`"
echo "push branch? \`ghpush "$(git branch --show-current)"\`"
echo "force-push branch? \`ghpush +"$(git branch --show-current)"\`"
return
fi
if [ "$1" = "!" ]; then
echo git push "https://**APIKEY**@github.com/**USERNAME**/"$var2""
git push "https://**APIKEY**@github.com/**USERNAME**/"$var2""
return
fi
echo git push "https://**APIKEY**@github.com/**USERNAME**/"$var2"" "$@"
git push "https://**APIKEY**@github.com/**USERNAME**/"$var2"" "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment