| 1 | In addition to the steps outlined by GitTips we have put together a wrapper script around git-commit that can be used to commit to multiple branches. Simply save this script as git-commit somewhere on your PATH. |
| 2 | |
| 3 | You can use it like so: |
| 4 | {{{ |
| 5 | #!sh |
| 6 | $ git-commit -b some_branch -m "some commit message" |
| 7 | }}} |
| 8 | |
| 9 | '''git-commit''' |
| 10 | {{{ |
| 11 | #!python |
| 12 | #!/usr/bin/python |
| 13 | # |
| 14 | # Copyright (C) 2010 Damien Churchill |
| 15 | # |
| 16 | # This program is free software; you can redistribute it and/or modify |
| 17 | # it under the terms of the GNU General Public License as published by |
| 18 | # the Free Software Foundation; either version 3, or (at your option) |
| 19 | # any later version. |
| 20 | # |
| 21 | # This program is distributed in the hope that it will be useful, |
| 22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | # GNU General Public License for more details. |
| 25 | # |
| 26 | # You should have received a copy of the GNU General Public License |
| 27 | # along with this program. If not, write to: |
| 28 | # The Free Software Foundation, Inc., |
| 29 | # 51 Franklin Street, Fifth Floor |
| 30 | # Boston, MA 02110-1301, USA. |
| 31 | |
| 32 | import sys |
| 33 | import subprocess |
| 34 | |
| 35 | GIT = '/usr/bin/git' |
| 36 | GIT_BRANCH = '/usr/lib/git-core/git-branch' |
| 37 | GIT_COMMIT = '/usr/lib/git-core/git-commit' |
| 38 | GIT_CHECKOUT = '/usr/lib/git-core/git-checkout' |
| 39 | GIT_FORMAT_PATCH = '/usr/lib/git-core/git-format-patch' |
| 40 | |
| 41 | if __name__ == '__main__': |
| 42 | |
| 43 | branches = [] |
| 44 | git_args = [] |
| 45 | |
| 46 | args = sys.argv[1:] |
| 47 | |
| 48 | while args: |
| 49 | arg = args.pop(0) |
| 50 | if arg in ('-b', '--branch'): |
| 51 | branches.append(args.pop(0)) |
| 52 | elif arg.startswith('--branch='): |
| 53 | branches.append(arg[9:]) |
| 54 | else: |
| 55 | git_args.append(arg) |
| 56 | |
| 57 | # Find out the current branch |
| 58 | current_branch = None |
| 59 | local_branches = [] |
| 60 | p = subprocess.Popen([GIT_BRANCH], stdout=subprocess.PIPE) |
| 61 | for line in p.stdout: |
| 62 | branch = line[2:].strip() |
| 63 | local_branches.append(branch) |
| 64 | if line[0] != '*': |
| 65 | continue |
| 66 | current_branch = branch |
| 67 | |
| 68 | for branch in branches: |
| 69 | if branch not in local_branches: |
| 70 | print >> sys.stderr, 'invalid branch: %s' % branch |
| 71 | sys.exit(1) |
| 72 | |
| 73 | subprocess.call([GIT_COMMIT] + git_args) |
| 74 | |
| 75 | for branch in branches: |
| 76 | subprocess.call([GIT_CHECKOUT, branch]) |
| 77 | p1 = subprocess.Popen([GIT_FORMAT_PATCH, '-k', '--stdout', '-1', |
| 78 | current_branch], stdout=subprocess.PIPE) |
| 79 | p2 = subprocess.Popen([GIT, 'am', '-3', '-k'], stdin=p1.stdout) |
| 80 | p2.communicate() |
| 81 | }}} |