Skip to content

Commit 83d0217

Browse files
gfzdwinterhive
authored andcommitted
Add option to push all branches to a remote repo at one time
Signed-off-by: Chris Grant <chrisgrant@resoluteoil.com>
1 parent b0d89ac commit 83d0217

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
@@ -972,7 +972,9 @@ def push(remote = nil, branch = nil, opts = nil)
972972
arr_opts = []
973973
arr_opts << '--mirror' if opts[:mirror]
974974
arr_opts << '--delete' if opts[:delete]
975-
arr_opts << '--force' if opts[:force] || opts[:f]
975+
arr_opts << '--force' if opts[:force] || opts[:f]
976+
arr_opts << '--all' if opts[:all] && remote
977+
976978
Array(opts[:push_option]).each { |o| arr_opts << '--push-option' << o } if opts[:push_option]
977979
arr_opts << remote if remote
978980
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)