Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push to github with custom commit message with npm scripts?

In my package.json I have this

  "scripts": {
    "start": "gulp serve",
    "git": "git add . && git commit -m 'some-message' && git push --all"
  },

In the terminal I run npm run git and the changes are pushed. But how can I change the commit message on the fly? For example npm run git MESSAGE='another commit'

like image 822
relidon Avatar asked Jun 09 '17 13:06

relidon


People also ask

How do I add a commit message to GitHub?

On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter. In your text editor, edit the commit message, and save the commit. You can add a co-author by adding a trailer to the commit.

Can I change commit message after pushing?

Changing the latest Git commit message If the message to be changed is for the latest commit to the repository, then the following commands are to be executed: git commit --amend -m "New message"

What is the git command for committing to a repository with a commit message?

The easiest way to create a Git commit with a message is to execute “git commit” with the “-m” option followed by your commit message.


1 Answers

A solution involving some npm trickery might consist of:

"scripts": {
  "git": "git add . && git commit -m",
  "postgit": "git push --all"
},

To be called like:

npm run git -- "Message of the commit"

or:

npm run git -- Message
like image 176
Andrea Carraro Avatar answered Oct 13 '22 01:10

Andrea Carraro