Skip to main content
  1. Articles/

Building New Go Project

Ahmad Obay
Author
Ahmad Obay

Inspired by https://github.com/golang/go/wiki/Modules

In this page, I list my approach of starting a new Go project and have it Git initiated and commited to GitHub.

The idea here is to have a short stub as a starting point where I can then start adding code quickly.

1. Install hub
#

hub is the command line tool used to communicate with GitHub. You can easily install it using brew.

brew install hub

2. Create the repo in GitHub
#

APP_NAME="my-new-go-project"
APP_DIR="/your/app/path/you/want/to/use"
mkdir -p $APP_DIR/$APP_NAME
cd $APP_DIR/$APP_NAME
go mod init github.com/obay/$APP_NAME
cat <<EOF > main.go
package main

import (
    "fmt"
)

func main() {
    fmt.Println("Hello, World")
}
EOF

wget -q https://raw.githubusercontent.com/github/gitignore/master/Go.gitignore -O .gitignore
touch README.md
git init -q
git remote add origin https://github.com/obay/$APP_NAME
git add .
git commit -m "Initial import"
hub create -p
git push --set-upstream origin master
code .