DEV Community

Dipsan Kadariya
Dipsan Kadariya

Posted on • Edited on

3

Automate Git Commands with Shell Scripts 🚀 | Boost Your Workflow 📜

Git Automation Script

Overview

This repository contains a PowerShell script designed to automate common Git operations.This script is designed to work globally across any project on your system.Once configured, the script simplifies the process of staging changes, committing with a message, and pushing updates to a remote repository.

Features

  • Automate Git Operations: Add all changes, commit with a message, and push to the remote repository with a single command.
  • Easy to Use: Run the script with a custom commit message to handle the Git workflow.

Setup Instructions

Follow these steps to set up and use the git-automation.ps1 script:

1. Create the Script

  1. In a text editor, create a new file and save it as git-automation.ps1 (or any preferred name).
  2. Add the following content to the file:

    if ($args.Length -eq 0) {
        $COMMIT_MSG = "Auto-commit"
    } else {
        $COMMIT_MSG = $args[0]
    }
    
    git add .
    git commit -m $COMMIT_MSG
    git push
    

2. Create a Directory for the Script

  1. Open PowerShell and run:

    mkdir C:\Scripts
    
  2. Move your script to this directory:

    move C:\Users\dipsa\Desktop\git-automation.ps1 C:\Scripts\
    

3. Add the Directory to PATH

  1. Click "Environment Variables."
  2. In "System variables," select Path and click "Edit."
  3. Click "New" and add:

    C:\Scripts
    
  4. Click "OK" to save and close the dialog boxes.

4. Set Execution Policy

  1. Open PowerShell and run:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
  2. Confirm by typing Y if prompted.


Usage

To use the script, run the following command from any project directory:


powershell
git-automation.ps1 "commit-message"
Enter fullscreen mode Exit fullscreen mode

Billboard image

Synthetic monitoring. Built for developers.

Join Vercel, Render, and thousands of other teams that trust Checkly to streamline monitor creation and configuration with Monitoring as Code.

Start Monitoring

Top comments (2)

Collapse
 
king_triton profile image
King Triton •

This is fantastic! I've been looking for a way to streamline my Git workflow, and this script seems like it will save me a lot of time. The step-by-step setup instructions are also very clear and easy to follow. I especially appreciate the flexibility to customize the commit message. Can't wait to give this a try in my next project! Thank you for sharing!

Collapse
 
dipsankadariya profile image
Dipsan Kadariya •

Thank you so much for you feedback. Its my pleasure to be able to help.
This script is designed to work globally across any project on your system. so once you have made the configuration, you can use it any project without any additional steps.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay