Search code examples
gitzshgit-amend

Automating commit amend procedure


I am finding myself annoyed at having to run the full procedure to amend commits in git and I was wondering which was the best way of automate them. So, instead of doing this:

$> git add .
$> git commit --amend
$> git push -f

I'd love to do this

$> amend_commit

Is shell scripting the only way to do it? I am using ZSH.

Thank you all.


Solution

  • While it is a pretty bad idea to automate a forced push, as it rewrites the history and everyone else working with the same repository will hate you, you can also define a git alias instead of a shell alias like

    git config alias.amend '!git add . && git commit --amend && git push -f'
    

    or if you don't want to edit the commit message, then

    git config alias.amend '!git add . && git commit --amend -C HEAD && git push -f'
    

    and then you can do git amend to use it.