2

After a review, i need to change some code and repush all my change code on the remote branch.

So i would like to automate on git with an alias (ex: git repushall) these different commands:

git add . git commit --amend (and ctrl + x) git push --force-with-lease

I know it's in the .gitconfig file

Do you have any idea ?

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
Tim
  • 162
  • 2
  • 10

1 Answers1

5

Add the --no-edit flag to the commit command to skip the editor opening.

To link commands, you could simply separate them with ;, but as Philippe mentionned in comment, it's often more effective to chain them with &&, then each command will only run if the previous one returned a 0 (no error) code.

git config --global alias.repushall '!git add . && git commit --amend --no-edit && git push --force-with-lease'
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • Is there a reason not to pipe the command with `&&` because most of the case git return code is 0? – Philippe Jan 03 '20 at 10:42
  • 1
    @Philippe No, you're right, both ways work, but it's indeed safer to link commands with `&&` to stop next commands if one fails. Editing to mention it. – Romain Valeri Jan 03 '20 at 11:36
  • 2
    @Philippe It's not "piping", it's "and'ing". Piping symbol is `|` – phd Jan 03 '20 at 14:42
  • @phd I didn't dare to correct it myself since Philippe was already correcting *me* on the technical substance, and the context made it clear enough but... you're right :-) That being said, "and'ing" sounds (and looks) awful. And "&&ing" is probably worse. – Romain Valeri Jan 03 '20 at 14:44
  • The proper term from the logic theory and computer science is [conjunction](https://en.wikipedia.org/wiki/Logical_conjunction). – phd Jan 03 '20 at 14:49
  • @phd I know it's not strictly speaking "piping" (and I hesitated when writing it) but I didn't find a better word (as neither a english native speaker nor a bash native writer) – Philippe Jan 03 '20 at 15:05