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

Ritesh SinghRitesh Singh
2 min read

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 CLI

  • Pushes 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

Project

๐Ÿ“‚ GitHub Repo

[โœ๏ธ Blog Post] (https://ritesh-devops.hashnode.dev)

๐Ÿ”— LinkedIn


๐Ÿ’ฌ Letโ€™s Connect!

๐Ÿ’ฌ Drop your feedback or suggestions here or on LinkedIn. Letโ€™s grow together! #100DaysOfDevOps #Bash #GitHubCLI #DevOpsTools # github

0
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