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

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

Top comments (0)