๐ Day 19: Build a Local Git + Bash Automation Tool


Welcome to Day 19 of my #100DaysOfDevOps journey! Today, I built a simple yet powerful Git automation tool using Bash. This tool helps me instantly initialize new projects, commit them, create a GitHub repo, and push โ all in a few seconds! ๐ปโก
๐ฏ Goal
To create a script that:
Takes a project name (and optional GitHub visibility)
Initializes a local Git repo
Commits initial code
Creates a GitHub repo using the
gh
CLIPushes everything automatically ๐
๐ง Why This Matters
As a DevOps engineer, automation is key ๐. Repeating the same Git + GitHub setup over and over wastes time. This tool streamlines that process so I can focus more on writing and deploying code!
๐ The Script: autogit.sh
#!/bin/bash
PROJECT_NAME=$1
VISIBILITY=${2:-public}
DATE=$(date)
LOG_FILE="$HOME/.autogit_log.txt"
if [ -z "$PROJECT_NAME" ]; then
echo "โ Please provide a project name: ./autogit.sh <project_name> [public|private]"
exit 1
fi
if [ -d "$PROJECT_NAME" ]; then
read -p "โ ๏ธ '$PROJECT_NAME' already exists. Overwrite it? (y/n): " choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
rm -rf "$PROJECT_NAME"
echo "๐๏ธ Old folder removed."
else
echo "โ Operation canceled."
exit 1
fi
fi
mkdir "$PROJECT_NAME" && cd "$PROJECT_NAME" || exit
echo "# $PROJECT_NAME" > README.md
echo -e "๐ Project: $PROJECT_NAME\n๐ Created: $DATE" >> README.md
git init
git add .
git commit -m "Initial commit by AutoGit"
git branch -M main
gh repo create "ritesh355/$PROJECT_NAME" --$VISIBILITY --source=. --remote=origin --push
echo "$DATE - Project '$PROJECT_NAME' created and pushed [$VISIBILITY]" >> "$LOG_FILE"
echo "โ
'$PROJECT_NAME' successfully created and pushed to GitHub!"
---
##๐ป How to Use It
```bash
chmod +x autogit.sh
./autogit.sh my_cool_project
You can also set visibility to private.
๐ ๏ธ Requirements
Git installed (git --version)
GitHub CLI authenticated (gh auth login)
GitHub account with proper permissions
๐ Example Output
๐ฆ Starting AutoGit setup for: my_cool_project
Initialized empty Git repository
โจ Created README.md
โ
Pushed to GitHub: https://github.com/ritesh355/my_cool_project
- Note replace my_cool_project with your project folder name and give your github link
๐ My Work
[โ๏ธ Blog Post] (https://ritesh-devops.hashnode.dev)
๐ฌ Letโs Connect!
๐ฌ Drop your feedback or suggestions here or on LinkedIn. Letโs grow together! #100DaysOfDevOps #Bash #GitHubCLI #DevOpsTools # github
Subscribe to my newsletter
Read articles from Ritesh Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ritesh Singh
Ritesh Singh
Hi, Iโm Ritesh ๐ Iโm on a mission to become a DevOps Engineer โ and Iโm learning in public every single day.With a full-time commitment of 8โ10 hours daily, Iโm building skills in: โ Linuxโ Git & GitHubโ Docker & Kubernetesโ AWS EC2, S3โ Jenkins, GitHub Actionsโ Terraform, Prometheus, Grafana I post daily blogs on Hashnode, push projects to GitHub, and stay active on LinkedIn and Twitter/X. Letโs connect, collaborate, and grow together ๐ #100DaysOfDevOps #LearningInPublic #DevOps