DEV Community

Cover image for Learn how to automate git add, commit and push commands by chaining them using Gcript
Ankit Mishra
Ankit Mishra

Posted on

Learn how to automate git add, commit and push commands by chaining them using Gcript

Gcript is a nodejs cli tool written in typscript to automate daily used git processes and provide utilities based on git. Gcript can be used to chain git commands like git add, git push etc. To see the npm package click here.

Read this documentation to get full understanding of gcript:

Installation

Install gcript as a global npm package and then you will be able to use gcript for any project on your machine. But if you wish to install it in a specific project, install it as a dev dependency because there is no need for gcript when your project is in production.

Install using npm

npm i -g gcript
Enter fullscreen mode Exit fullscreen mode

Install using yarn

yarn global add gcript
Enter fullscreen mode Exit fullscreen mode

Please make sure to install gcript either as global or local package otherwise conflict between local and global package might introduce unexpected behaviors.

Commands

Gus provides commands to do operation such as running the main thread or configuring the gcript etc. These commands can be further configured for a specific use case using command options or global configurations.

How to use commands

To use gcript commands simply right the gcript command in your terminal or cmd as shown below:

gcript <command> [options]
Enter fullscreen mode Exit fullscreen mode

Run command

Run command is like main thread of gcript. Run command automatically chains and execute the git add, commit and push commands with all the extra information these commands need. In this chain of process gcript will only execute commands that are necessary. For example, if all files and changes are already staged, gcript will not execute git add command. Failing of any command in this chain will kill the further process. When you run this command, gcript will automatically check if there is a git repository present from where you ran the command. If it will not find any git repository, gcript will initialize a git repository for you. So there is no need to worry about whether you are using the gcript run command inside a git repository or not. Gus will automatically suggest you to add a remote, if it will not find any remotes in the repository.

Usage

gcript run [options]
Enter fullscreen mode Exit fullscreen mode

Options

  • -b | --branch <branch> : Use this option to use another branch for git push command in the chain of process. By default gcript uses main branch for git push command.
  • -f | --file <...files> : Use this option to only include specified files in the git add command in the chain of process. You can specify multiple files with this option by separating file names with a whitespace. For example: gcript run -f file1.js file2.js. In the absence of this option gcript will execute git add . command.
  • -m | --message <message> : Use this option to specify a commit message. In the absence of this option gcript will stop the chain of process at git commit command and ask you to enter a commit message and resume the process as per your response.
  • -r |--remote <remote> : Use this option to specify a remote for git push command in the chain of process. In absence of this option, gcript will check the current remotes available in that repository. If gcript will not find any remotes it will ask you to add a remote otherwise it will display the list of available remotes and ask you to choose one unless you have set global configuration for remote property or the origin remote is available.

Config command

Config command deals with global configurations of gcript. It stores the configurations as json at the installation location of gcript. Configuration can be changed or viewed at any time using config command. Note that local configurations take precedence over global configurations.

Usage

gcript config [options]
Enter fullscreen mode Exit fullscreen mode

Properties

  • remote : Holds the remote that will be used while executing git push command in the chain of process. This property is related to run command.
  • branch : Value of this property will be used while executing git push command in the chain of process. This property is related to run command.
  • trace : If this property is equal to true, after any process complete log will be displayed.

Options

  • -s | --set <property=value> : Use this option to change a global configuration. For example gcript config --set remote=origin will set the global configuration property remote equal to origin.
  • -l | --list [property] : Use this option to view global configurations. If no property will be specified with this option, gcript will view the all global configuration of gcript. For example gcript config -l branch will only display the value of branch property while gcript config -l will display all global configurations.

Help command

Help command display the help for the commands. For example gcript help config will display help for config command.

Usage

gcript help <command>
Enter fullscreen mode Exit fullscreen mode

Upgrade command

Upgrade command checks the availability of any latest version of gcript and updates the gcript accordingly.

Usage

gcript upgrade
Enter fullscreen mode Exit fullscreen mode

Version command

Version command displays the current version of gcript along with a notice if any latest version of gcript is available.

Usage

gcript version
Enter fullscreen mode Exit fullscreen mode

Global options

Global options can be used with all commands of gcript. Global options can be placed after or before command specific options.

Usage

gcript <command> [global-options] [options]
Enter fullscreen mode Exit fullscreen mode

List

  • -t | --trace : Use this option to see the complete log of process executed by any command of gcript. For example gcript run -t will display the complete log at every moment rather than showing a short message.

  • -h | --help : Use this option to view help for any command of gcript. For example gcript config -h will display the help for config command , same as gcript help config.

Top comments (0)