4

I would really love a specialized git alias / bash function that can do the following.

git add -A
git commit -m "$MESSAGE"
git push origin master

All with a single command.

gacp
> My message
CONTENTS OF COMMIT
CONTENTS OF PUSH

Can this be done? Could someone share some sample code? Is there a native git function that can do this?

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424

4 Answers4

4

If you are on linux, just write a shell script or create an alias

For example.

#!/usr/bin/sh

set -x  # Output executed commands
set -e  # Make script fail as soon as one command fails

read MESSAGE

git add -A
git commit -m "$MESSAGE"
git push origin master
Jo So
  • 25,005
  • 6
  • 42
  • 59
  • 1
    In addition, name it `git-foo`, put it somewhere in your `$PATH`, and then you can run it either as `git-foo` or `git foo`. – twalberg Dec 05 '12 at 17:01
  • How, in linux / unix can you make a "console" type of interface. I hate adding quotes for the first argument and would love it if right after I typed the command there was a new line with some kind of identifier like `>` then this would be the message / argument. – ThomasReggi Dec 05 '12 at 17:30
1

on my windows machine . i have set up this bashrc alias to make the entire process more simple.

  • create / locate your .bashrc - refer stack overflow thread

  • add the following line to file

    alias gacp='echo "enter commit message : " && read MSG && git add . && git commit -m "$MSG" && git push'

  • reload .bashrc / close and reopen your shell

  • now you can do the entire process with gacp command .
Community
  • 1
  • 1
Sojan Jose
  • 3,168
  • 6
  • 33
  • 52
0

The first two commands can be launch with :

git commit -a -m "$MESSAGE"

Then, you can check other commands :

git pull --rebase 
git rebase -i

before to do a git push.

Fabrice31
  • 770
  • 11
  • 25
0

Refer to the answer here: git add, commit and push commands in one?

You can try gitu.

For the first time (node js has to be installed):

npm install -g git-upload

After that:

gitu COMMIT_MSG

To issue those three commands at once.

The good thing is that you don't have to worry when you reinstall your system or when you want to do this on different computers and No file modification is needed. This also work on different platforms (not just Linux and Mac, but also Windows) just that you have to install npm and nodejs (git of course).

Fries
  • 349
  • 1
  • 5
  • 10