I would like to sign off all commits on a branch that I have finished and want to send to an upstream project (e.g. via a pull request on GitHub).
A recommended way I've found is to use
git rebase -i [base-commit]
# Set all commits to "edit"
git commit --amend --signoff # do this for all commits
How can I do this automatically, in one non-interactive command?
With Git 2.13 (Q2 2017), no more "git commit --amend --signoff" needed:
See commit 9f79524 (18 Apr 2017), and commit 0fb3c4f, commit b7cc705 (15 Apr 2017) by Giuseppe Bilotta (Oblomov).
(Merged by Junio C Hamano -- gitster -- in commit 768c7cb, 26 Apr 2017)
rebase: pass--[no-]signoffoption togit amThis makes it easy to sign off a whole patchset before submission.
The git rebase man page now includes:
--signoff:
This flag is passed to '
git am' to sign off all the rebased commits.
Incompatible with the--interactiveoption.
Update (one year later, May 2018) "git rebase" has learned to honor "--signoff" option when using
backends other than "am" (but not "--preserve-merges").
rebase: extend--signoffsupportAllow
--signoffto be used with--interactiveand--merge.
In interactive mode only commits marked to be picked, edited or reworded will be signed off.The main motivation for this patch was to allow one to run '
git rebase --exec "make check" --signoff' which is useful when preparing a patch series for publication and is more convenient than doing the signoff with another --exec command.This change also allows
--rootwithout--ontoto work with--signoffas well (--rootwith--ontowas already supported).
It is also more robust:
rebase -p: error out if--signoffis given
rebase --preserve-mergesdoes not support--signoffso error out rather than just silently ignoring it so that the user knows the commits will not be signed off.
It turns that git aliases can do this quite nicely. Put into your ~/.gitconfig:
[alias]
# Usage: git signoff-rebase [base-commit]
signoff-rebase = "!GIT_SEQUENCE_EDITOR='sed -i -re s/^pick/e/' sh -c 'git rebase -i $1 && while git rebase --continue; do git commit --amend --signoff --no-edit; done' -"
Here's also a Gist for it.
You use it just like git rebase; the picks are automatically flipped to edits using sed and --no-edit makes sure to not open an editor for every single commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With