Skip to content

Commit 81db45e

Browse files
committed
Add option to push all branches to a remote repo at one time
Signed-off-by: Chris Grant <chrisgrant@resoluteoil.com>
1 parent 0bb965d commit 81db45e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ g.push(g.remote('name'))
345345
# delete remote branch
346346
g.push('origin', 'remote_branch_name', force: true, delete: true)
347347

348+
# push all branches to remote at one time
349+
g.push('origin', all: true)
350+
348351
g.worktree('/tmp/new_worktree').add
349352
g.worktree('/tmp/new_worktree', 'branch1').add
350353
g.worktree('/tmp/new_worktree').remove

lib/git/lib.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,9 @@ def push(remote = nil, branch = nil, opts = nil)
984984
arr_opts = []
985985
arr_opts << '--mirror' if opts[:mirror]
986986
arr_opts << '--delete' if opts[:delete]
987-
arr_opts << '--force' if opts[:force] || opts[:f]
987+
arr_opts << '--force' if opts[:force] || opts[:f]
988+
arr_opts << '--all' if opts[:all] && remote
989+
988990
Array(opts[:push_option]).each { |o| arr_opts << '--push-option' << o } if opts[:push_option]
989991
arr_opts << remote if remote
990992
arr_opts_with_branch = arr_opts.dup

tests/units/test_push.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ class TestPush < Test::Unit::TestCase
9696
assert_command_line(expected_command_line, git_cmd, git_cmd_args)
9797
end
9898

99+
test 'push with all: true' do
100+
expected_command_line = ['push', '--all', 'origin']
101+
git_cmd = :push
102+
git_cmd_args = ['origin', all: true]
103+
assert_command_line(expected_command_line, git_cmd, git_cmd_args)
104+
end
105+
99106
test 'when push succeeds an error should not be raised' do
100107
in_temp_dir do
101108
Git.init('remote.git', initial_branch: 'master', bare: true)

0 commit comments

Comments
 (0)