This shell script, with only a few configurations, has the goal of initializing a project on Gitlab.com without having to go through the go through the website's ui.
This means: Let's say you just a project with a few source files, but you haven't done anything with git yet. The goal of this script is to allow you to write something like git-init-remote <my_repository_name>
on the command line and have both the project on your personal gitlab.com and the local git repository.
#!/bin/sh
repo=$1
token=<YOUR-PRIVATE-TOKEN> # You get this from https://gitlab.com/-/profile/personal_access_tokens
username=<YOUR-USERNAME>
test -z $repo && echo "Repo name required." 1>&2 && exit 1
curl --request POST --header "Private-Token: $token" --header "Content-Type: application/json" --data "{\"name\":\"$repo\"}" "https://gitlab.com/api/v4/projects"
echo "\nDone initializing on remote."
echo "\nCreating local git repository..."
git init
git remote add origin https://gitlab.com/$username/$repo.git
git add .
git commit -m "Initial commit"
git push -u origin master
echo "\nDone."
I would like to have any of your thoughts on how this can break and how scalable this can go. I had trouble finding similar scripts on the web so I felt like a had to write here.