10

I do the following string of commands for git and my fingers are getting tired of typing them. :)

git add .
git commit -m 'Some message'
git push
cap deploy

How can I combine those (including adding a message) into a single command, like "git booyah" or something?

Shpigford
  • 24,748
  • 58
  • 163
  • 252
  • possible duplicate ;; http://stackoverflow.com/questions/16709404/how-to-automate-the-commit-and-push-process-git – dreftymac Oct 25 '14 at 04:01

5 Answers5

9

You can also combine the frequent commands in one line:

$ git add . | git commit -m 'Some message' | git push | cap deploy

Next time you just need the Up arrow to get it back, then push Enter

eQ19
  • 9,880
  • 3
  • 65
  • 77
8

You could define a git alias calling a script

Since version 1.5.0, Git supports aliases executing non-git commands, by prefixing the value with "!".
Starting with version 1.5.3, git supports appending the arguments to commands prefixed with "!", too.

Be defining a function within your alias, you can avoid the explicit call to 'sh -c'

[alias]
        publish = "!f() { git add . ; git commit -m \"$1\" ; git push ; cap deploy ; }; f"

or, after the suggestion of Pod in his answer:

[alias]
        publish = "!f() { git commit -a -m \"$1\" ; git push ; cap deploy ; }; f"

(to be tested)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 2
    Be careful with those double-quotes. When I tried this example, !f expanded to the last 'find' command that I had run in my bash history. Still pointed me in the right direction, though. – nocash Oct 15 '10 at 02:36
6

This is not an answer to your question (my answer would be: make a bash/batch script).

I say this: Don't do git add . This will add every change and all untracked files in the current directory and it's descendants. You might not want these untracked files in your directory and you'll accidently add them, especially if you're typing ti as much as you claim you are.

Instead do git add -u. Even better, skip the add stage and do git commit -a -m"blah", which saves you an entire line, which is apparently something you are keen to avoid.

Pod
  • 3,938
  • 2
  • 37
  • 45
4

I just use semicolons to combined into one command line:

git add .; git commit -m "Some message"; git push; cap deploy
Michael Behrens
  • 911
  • 10
  • 8
0

You can create a file named commands.txt. Paste your git commands in that text file.

// Contents of commands.txt

git add .
git commit -m 'Some message'
git push
cap deploy

After that, rename the commands.txt to commands.bat. Now, you can just double click the commands.bat file or run the following command:

call commands.bat

This will do the trick.

Abu Noman Md Sakib
  • 322
  • 2
  • 5
  • 20