From 3d19f6a9c17fb445fb8ead61c5e61dc3eadf5017 Mon Sep 17 00:00:00 2001 From: Jeff Hykin Date: Mon, 29 May 2023 09:53:19 -0500 Subject: [PATCH] add git_push_all_branches_to_url --- .../094_000_jeffs_git_shortcuts.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/settings/during_start/094_000_jeffs_git_shortcuts.sh b/settings/during_start/094_000_jeffs_git_shortcuts.sh index 8cdbc23..a070e72 100644 --- a/settings/during_start/094_000_jeffs_git_shortcuts.sh +++ b/settings/during_start/094_000_jeffs_git_shortcuts.sh @@ -478,6 +478,34 @@ git_delete_submodule () { git rm -f "$the_path" } +git_push_all_branches_to_url () { + url="$1" + + temp_remote_name="@__temp_origin__" + git remote remove "$temp_remote_name" 2>/dev/null + # Add the target repository as a remote + git remote add "$temp_remote_name" "$url" + + # Fetch the remote branches + git fetch "$temp_remote_name" + + # Try pushing + for branch in $(git branch -r | grep -v HEAD | grep -v "$temp_remote_name"); do + branch_name=${branch#*/} + + # Checkout each branch + git checkout -b "$branch_name" "$branch" || git checkout "$branch_name" + + # Push the rewritten branch to the target repository + if ! git push "$temp_remote_name" "$branch_name"; then + echo "An error occurred while pushing branch: $branch_name" + break + fi + done + + git remote remove "$temp_remote_name" +} + # self submodule # git submodule add -b jirl --name "jirl" -- https://github.com/jeff-hykin/model_racer.git ./source/jirl