DEV Community

Cover image for Automate Git in 3 lines of code
C I R L O R M ⚡
C I R L O R M ⚡

Posted on

6 2

Automate Git in 3 lines of code

Hi there, I am going to show you how to automate your most used git commands in just three lines of code.
Our program will be able to run add, commit and push commands for us in just on call. Let me show you.

Writing the script

We are using shell script or bash to run our commands for us.

  1. We will have to create a file name script.sh You can change the name to anything but maintain the .sh extension.

2.Then we write the code

#!/bin/bash

# This is the add command that will run add all your modified files to the working tree
git add .

# The git command takes an argument when running the script to use as the commit message
git commit -m "$1"

# Finally we push our code.
git push
Enter fullscreen mode Exit fullscreen mode

And that's it, we are done.
Then we can run the script by running bash script.sh "commit message here" in the terminal.

Thank you for reading.
Twitter
Website

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more