Last active
May 16, 2022 14:52
-
-
Save Vac1911/36571699986bbc440857a2602e14331c to your computer and use it in GitHub Desktop.
Sets up git authentication (for github) automatically
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
# Install GitHub CLI | |
GH=$HOME/.local/bin/gh | |
command -v gh | |
if [ "$(command -v gh)" ]; then | |
# GitHub CLI is globally installed | |
GH="$(which gh)" | |
elif [ -f "$GH" ]; then | |
# GitHub CLI is locally installed | |
echo "already installed" | |
else | |
# GitHub CLI needs to be installed | |
VERSION=`curl "https://api.github.com/repos/cli/cli/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c2-` | |
curl -sSL https://github.com/cli/cli/releases/download/v${VERSION}/gh_${VERSION}_linux_amd64.tar.gz -o gh_${VERSION}_linux_amd64.tar.gz | |
tar xvf gh_${VERSION}_linux_amd64.tar.gz | |
mkdir $HOME/.local/bin | |
mv gh_${VERSION}_linux_amd64/bin/gh $HOME/.local/bin/ | |
rm -rf gh_${VERSION}_linux_amd64 | |
rm gh_${VERSION}_linux_amd64.tar.gz | |
echo "alias gh='${GH}'" >> $HOME/.bashrc | |
source ~/.bashrc | |
fi | |
# Authenticate through GitHub CLI and get username | |
`$GH auth login` | |
GITUSERNAME=`$GH api user | grep -oE '"login":"[^,]+"' | sed -E 's/.*"([^"]+)".*/\1/'` | |
# Setup git credentials | |
`$GH auth setup-git` | |
git config --global user.name $GITUSERNAME | |
git config --global user.email ${GITUSERNAME}@github.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: