Skip to content

Instantly share code, notes, and snippets.

@ThePyProgrammer
Created July 18, 2021 14:28
Show Gist options
  • Save ThePyProgrammer/3480f781b7423eb35786c1c423be19c9 to your computer and use it in GitHub Desktop.
Save ThePyProgrammer/3480f781b7423eb35786c1c423be19c9 to your computer and use it in GitHub Desktop.
A simple shell script to run commits in a single line
# First let's check the status
git status
# We now add the file as in the arguments
for i in $(seq 2 $#);
do git add ${!i};
done
# Commit files based on first argument
git commit -m "$1"
# Push repo to origin
git push origin
# Check status again
git status
@ThePyProgrammer
Copy link
Author

Usage:

alias commit="bash commit.sh"
# ^ address of the file in the ThreeBody repo
commit <commit message> *<files to be committed>

@ThePyProgrammer
Copy link
Author

ThePyProgrammer commented May 23, 2022

This is actually really unnecessary.

I guess the best way to code this is as follows:

In your ~/.bashrc:

function add() {
    # Create a function for adding files to git.
    git add $1
    echo "Commited $1"
}

function commit() {
    # First let's check the status
    git status


    # We now add the file as in the arguments
    for i in $(seq 2 $#);
        do add ${!i};
    done

    # Commit files based on first argument
    git commit -m "$1"

    # Push repo to origin
    git push origin

    # Check status again
    git status
}

export -f commit

Then in Git Bash:

$ commit "<commit message>" file1 file2 directory1/ directory2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment