Last active
September 27, 2024 14:26
-
-
Save tilap/2168b2afa7ad75d5a4f74da42011f1a2 to your computer and use it in GitHub Desktop.
BASH: Command to create a git repo from CLI
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
# USAGE: githubrepo name-of-the-repo | |
githubrepo() { | |
USERNAME=tilap | |
if [ $# -ne 1 ]; then | |
echo "You must provide the name of the repo"; \ | |
exit; \ | |
fi | |
local REPO=$1 | |
echo "Create repo $REPO on github"; | |
local RESPONSE=$(curl --write-out "%{http_code}\n" --silent --output /dev/null -i -u $USERNAME -d "{\"name\": \"$REPO\", \"auto_init\": true}" https://api.github.com/user/repos) if [ $RESPONSE -eq 201 ]; then | |
echo "Repository created on github"; \ | |
git init; \ | |
git remote add origin "[email protected]:$USERNAME/$REPO.git"; \ | |
else | |
echo "Error while creating the repo, received a $RESPONSE code" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment