Skip to content

Instantly share code, notes, and snippets.

@jamesmurdza
Last active March 18, 2023 09:29
Show Gist options
  • Save jamesmurdza/89b6b3a48f112f7a033d0419fa6c01f2 to your computer and use it in GitHub Desktop.
Save jamesmurdza/89b6b3a48f112f7a033d0419fa6c01f2 to your computer and use it in GitHub Desktop.
GitHub create new repo using access token
GITHUB_USERNAME=username
REPO_NAME=repo
# Get a token from here: https://github.com/settings/tokens
GITHUB_TOKEN=token
mkdir $REPO_NAME
cd $REPO_NAME
git init
touch README.md
git add README.md
git commit -m "Initial commit"
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-X POST \
-d "{\"name\": \"$REPO_NAME\", \"description\": \"A new repo!\"}" \
https://api.github.com/user/repos
echo "protocol=https
host=github.com
username=$GITHUB_USERNAME
password=$GITHUB_TOKEN" >> ./credentials
git config credential.helper "store --file=./credentials"
git push --set-upstream "https://github.com/$GITHUB_USERNAME/$REPO_NAME" main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment