Created
March 30, 2024 13:31
-
-
Save tosin2013/d3673c8fc5b6c19015672292c8f8fdca to your computer and use it in GitHub Desktop.
Universal Git Repository Merger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Source repository configuration (HTTPS) | |
source_repo_url="https://github.com/SOURCE_REPO_OWNER/SOURCE_REPO_NAME.git" | |
source_branch="main" | |
# Target repository configuration (SSH) | |
target_repo_url="[email protected]:TARGET_REPO_OWNER/TARGET_REPO_NAME.git" | |
target_branch="main" | |
# Temporary directory for cloning repositories | |
temp_dir=$(mktemp -d) | |
# Clone the source repository | |
git clone --branch "$source_branch" "$source_repo_url" "$temp_dir/source_repo" | |
# Clone the target repository | |
git clone --branch "$target_branch" "$target_repo_url" "$temp_dir/target_repo" | |
# Navigate to the target repository | |
cd "$temp_dir/target_repo" | |
# Add the source repository as a remote | |
git remote add source "$source_repo_url" | |
# Fetch the latest changes from the source repository | |
git fetch source | |
# Create a new branch for merging | |
git checkout -b "merge-from-source" | |
# Merge the changes from the source branch | |
git merge "source/$source_branch" | |
# Push the merged changes to the target repository | |
git push origin "merge-from-source" | |
# Clean up the temporary directory | |
rm -rf "$temp_dir" | |
echo "Merge completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment