Ok Boomer! Instant GitHub Repo Creation in One Command 🚀
Tags: productivity, programming, github, git
Published: 2024-02-01 22:04:18


## Boom Live Action GIFs 🤩

### On an existing folder/repo
![Existing Repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dcfq6eju6sxsj2mydh5y.gif)


### Creating a new folder/repo
![New repo/folder](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezqbml8wvxp8hs51s08v.gif)

## Quick Explanation / Installation
Hey DEV community! If you're anything like me, you frequently start new projects to experiment with ideas, and find yourself needing to manually create new repositories on GitHub for backups.

If so, you'll appreciate this little `boom` script I wrote a few years back. Simply copy/paste the code snippet below into your `.rc/.bashrc/.zshrc` file and you're ready to `boom` 🤯


> 👉 *Note:* This script uses the GitHub CLI. So make sure you've installed that if you haven't already. Instructions [here](https://cli.github.com/).


```sh
#!/bin/bash
# Function to quiet the output of a cmd unless it fails 

# Optional function I find handy for silencing the output of commands
quiet () {
	"$@" > /dev/null 2>&1
}

boom () {
	echo "Boom! Creating Git & GitHub repo. Please wait..."
        # If a param is passed, create a dir with that name and cd to it
	if [ $1 ]
	then
		quiet mkdir $1 && cd $1
		echo "Created folder $1"
	fi
        # Create README file if it doesn't already exist with directory name
	if [ ! -f README.md ]
	then
		quiet echo "# ${PWD##*/}" > README.md
		echo "Generated a README.md file"
	fi
	git init
	git add .
	git commit -m "Initial commit"
	gh repo create ${PWD##*/} --private --source=. --remote=origin
	git push -u origin main
	echo "Boom! Your repo is live: $(git config --get remote.origin.url)"
}

```

## How's it work? 🤔
The `boom` script simplifies repository creation into one straightforward command. Here's how you can use it:

### With Argument:
Running the script with an argument creates a new folder, navigates into it, generates a `README.md` file with the folder name as the title, initializes a new Git repository, adds all files, commits the changes, pushes the new repository to GitHub, and outputs the repository URL.

### Without Argument:
If run without an argument, the script generates a `README.md` file with the current folder name as the title, initializes a new Git repository, adds all files, commits the changes, pushes the new repository to GitHub, and outputs the repository URL.

## Notes 
- Customize your repository by adding a `.gitignore` file before running the script if you don't want to include all your files.
- By default, the script creates private GitHub repositories. Adjust this behavior by modifying the script.
Repositories can be deleted from GitHub using the command `hub delete -y repo-name`.


## Ok Boomer 👴🏻
Hope this saves you all some time! I've used variants of this script myself hundreds of times for over a decade now!

If you're interested in other things I've made to speed up our dev lives [check out the other post I wrote here](https://dev.to/tofudotdev/still-deploying-updates-to-toggle-maintenance-pages-i-was-too-lgj) recently about [Maintenance.dev](https://maintenance.dev), a new side project I launched that lets you get an instantly toggle-able customizable maintenance page for your own website with a single `<script>`, so you don't have to do any more manual deploys just to toggle maintenance pages.

Happy coding everyone! 🫡