0

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.

antogilbert
  • 176
  • 2
  • 12

3 Answers3

1

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.

Vampire
  • 35,631
  • 4
  • 76
  • 102
0

You can just create an alias. This should work:

alias amend_commit="git add . && git commit --amend && git push -f"
Christopher Schneider
  • 3,745
  • 2
  • 24
  • 38
0

You can cut out one of the steps by using the -a flag to git commit to auto-add any changes:

git commit -a --amend
git push -f

As another user has already commented, it seems dangerous to fold an automatic force-push into this workflow.

Amending an already pushed branch is advised against. I'd say it is something you should do relatively infrequently, unless you are using a workflow that allows for mutable feature branches (for rebasing, etc).

Benjamin
  • 1,221
  • 11
  • 28