Create GitHub Repo on a New Laravel Project

Adam Bailey • October 31, 2021

laravel configuration

Share:

This year, Laravel added a new feature to easily create a new git repository when creating a new project. This article explains how to use the GitHub CLI to go even further.

Installing GitHub CLI

In order to utilize the GitHub tooling for the laravel installer, you'll need to have git already installed, as well as GitHub CLI installed globally.

GitHub CLI brings GitHub to your terminal. Free and open source.

I simply installed the CLI using Homebrew, with brew install gh in the terminal. After installation, restart your terminal, and continue with the Laravel installation.

Installing Laravel

First, you'll need a basic understanding of how to install Laravel, and you'll need Composer installed beforehand. For the purposes of this article, we'll be building on macOS and using GitHub. You may use the official Laravel documentation to get you started.

To initialize git, you can now just supply a flag on the Laravel installer command. We will be focusing on the GitHub portion of this Laravel installation.

Initializing GitHub

To create a new repository on GitHub when installing the new Laravel project, simply supply the --github flag as follows:

1laravel new example-app --github

This will put your new project in a private repository at https://github.com/<your-account>/example-app.

To change the initial branch name to use main:

1laravel new example-app --github --branch="main"

To make your repo public, add the --public flag:

1laravel new example-app --github="--public"

Conclusion

That's about all there is to it! This saves a lot of time (and potential Googling) trying to set up a new repo and initialize git with a new Laravel project.

Happy coding!

You might like other posts in
laravel