Skip to content

Instantly share code, notes, and snippets.

@rafaelbeckel
Created January 30, 2020 03:03
Show Gist options
  • Save rafaelbeckel/63d4f372d6006cc0b92824443cae752b to your computer and use it in GitHub Desktop.
Save rafaelbeckel/63d4f372d6006cc0b92824443cae752b to your computer and use it in GitHub Desktop.
Create new Golang project and Github repository with one single command
# put that in your .bash_profile
function ng() {
mkdir $GOPATH/src/github.com/rafaelbeckel/$1 &&
cd $GOPATH/src/github.com/rafaelbeckel/$1 &&
git init &&
curl -u 'rafaelbeckel' https://api.github.com/user/repos -d "{\"name\":\"$1\", \"private\":true, \"gitignore_template\": \"Go\" }" &&
git remote add origin https://github.com/rafaelbeckel/$1
&& git pull origin master
&& touch main.go
&& code .;
}
# Usage: ng YOUR_REPO_NAME
# @TODO needs some cleanup, but it works as-is for me.
# Feel free to replace my name and "code" to your favorite editor
# @TODO start with a skeleton or a hello world instead of an empty file
@rafaelbeckel
Copy link
Author

I was annoyed that every time I started a new project in Go, I needed to manually create a new repository and the right path structure in my filesystem to match it.

So, I have created a command for it. It creates the repo in Github, clones it to the correct path in my filesystem, includes a Go .gitignore template, creates a main.go file, and fires up my favorite editor with the project opened up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment