[Repo Creation on One Command: Automate GitHub Setup Easily]
As engineers, we often find ourselves repeating the same administrative tasks multiple times a week. One such task that consistently disrupted my development flow was creating GitHub repositories.
The process was always the same: initialize a local Git repository, stage files, commit, then manually create a remote repository and set up the connection. While each step individually takes seconds, the cumulative time and context switching add up significantly. More importantly, this friction often becomes a psychological barrier: many small utilities, experiments, and prototypes never leave our local machines because the overhead seems disproportionate.
Yet every piece of code deserves to live in the cloud: whether it's a tiny automation script, a personal tool, or a half-baked experiment, pushing it remotely means you can access it from any machine, revisit it months later, or even let asynchronous AI agents like Google's Jules analyze and work with it. The repository creation process shouldn't be the bottleneck that keeps your code siloed.
In this guide, I'll share how I eliminated this repetitive workflow by creating a single Bash function that reduces a multi-step process to one command.
The problem
The typical workflow for creating a new GitHub repository looks like this:
git init
git add .
git commit -m "Initial commit"
gh repo create --source=. --push --privateFour commands, four opportunities for typos, four breaks in concentration. When you're spinning up multiple projects, prototypes, or microservices weekly, this becomes a noticeable friction point. More importantly, it's not just about time—it's about reducing cognitive load and maintaining flow state.
The solution: a single bash function
I consolidated these steps into a reusable function called gh-init-repo:
ghi() {
git init
git add .
git commit -m "Initial commit"
gh repo create --source=. --push --private
}This simple function reduces the entire process to a single command. I consider that you are using the GitHub CLI (gh) tool, and you successfully made authentication using your GitHub account via gh auth login.
How to install
Add the function to your ~/.bashrc file:
# Open your .bashrc
nano ~/.bashrc
# Paste this at the bottom:
ghi() {
git init
git add .
git commit -m "Initial commit"
gh repo create --source=. --push --private
}
# Save and reload
source ~/.bashrcThat's it. Now you can run gh-init-repo in any project directory.
Usage example
mkdir my-project && cd my-project
# ... create your files ...
ghiThe function handles everything: it initializes git, commits your files, creates a private GitHub repository, and pushes the code. No context switching, no manual steps, no typos.
