Skip to content

Add option to push all branches to a remote repo at one time #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ g.push(g.remote('name'))
# delete remote branch
g.push('origin', 'remote_branch_name', force: true, delete: true)

# push all branches to remote at one time
g.push('origin', all: true)

g.worktree('/tmp/new_worktree').add
g.worktree('/tmp/new_worktree', 'branch1').add
g.worktree('/tmp/new_worktree').remove
Expand Down
4 changes: 3 additions & 1 deletion lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,9 @@ def push(remote = nil, branch = nil, opts = nil)
arr_opts = []
arr_opts << '--mirror' if opts[:mirror]
arr_opts << '--delete' if opts[:delete]
arr_opts << '--force' if opts[:force] || opts[:f]
arr_opts << '--force' if opts[:force] || opts[:f]
arr_opts << '--all' if opts[:all] && remote

Array(opts[:push_option]).each { |o| arr_opts << '--push-option' << o } if opts[:push_option]
arr_opts << remote if remote
arr_opts_with_branch = arr_opts.dup
Expand Down
7 changes: 7 additions & 0 deletions tests/units/test_push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ class TestPush < Test::Unit::TestCase
assert_command_line(expected_command_line, git_cmd, git_cmd_args)
end

test 'push with all: true' do
expected_command_line = ['push', '--all', 'origin']
git_cmd = :push
git_cmd_args = ['origin', all: true]
assert_command_line(expected_command_line, git_cmd, git_cmd_args)
end

test 'when push succeeds an error should not be raised' do
in_temp_dir do
Git.init('remote.git', initial_branch: 'master', bare: true)
Expand Down