How to create an alias to execute multiple commands with git?

6

I would like to know how to create an alias for git that runs the following commands:

  • git add (all modified files)
  • git commit (including a message)
  • git push

I tried the following configuration in gitconfig:

[alias]
   upl = !git add -A && git commit -m "$2" && git push origin master

I would like to use the alias by passing a parameter to the message

git upl "cabecalho alterado"

Error message received

cpd@INFORMATICA-01 MINGW64 /c/wamp/www/alura_git/curso_git (master)
$ git upl "teste"
error: switch 'm' requires a value usage: git commit [<options>] [--] <pathspec>...
    
asked by anonymous 08.02.2017 / 15:40

2 answers

2

I was able to solve the problem using a function and creating the alias by the console itself

git config --global alias.upl '!func(){ git add -A && git commit -m "$1" && git push -q; }; func'
    
10.02.2017 / 16:13
0

The Error

cpd@INFORMATICA-01 MINGW64 /c/wamp/www/alura_git/curso_git (master) $
git upl "teste" error: switch 'm' requires a value usage: git commit
[<options>] [--] <pathspec>...

It is about trying to pass an empty commit message to the commit. The -m parameter specifies the commit message. By passing the $2 value in the

  

... commit -m "$2" ...

The second argument is passed as a parameter to -m , which in this case does not exist. In your case, you need to get the first argument from

  

upl "cabecalho alterado"

For this, you should use $1 value, thus

[alias]
   upl = !git add -A && git commit -m "$1" && git push origin master
    
08.02.2017 / 19:32