Skip to content

Instantly share code, notes, and snippets.

@christianc1
Last active December 14, 2022 00:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianc1/d61d878b3b73d3f1d322378c08e566b6 to your computer and use it in GitHub Desktop.
Save christianc1/d61d878b3b73d3f1d322378c08e566b6 to your computer and use it in GitHub Desktop.
Merging a repo
#!/bin/bash
# This is the target directory of the repo we are merging another repo into. (wp-content)
echo $1;
# This is the slug of what we are merging, used for directory and branch names (e360-fix-links)
echo $2;
# This is the remote url of the git directory (https://christianchung10up@bitbucket.org/wallstcheatsheet/e360-fix-links.git)
echo $3
# Say what we are doing...
echo "Merging $3 into ./$1 as $2"
# Move to (/root/wp-content)
cd $1
# Switch to refactoring branch and pull
git checkout feature/refactoring
git pull
# Branch from refactoring, creating a branch for our merging
git checkout -b feature/refactoring-add-plugin-$2
# Okay go back to the root (/root)
cd ..
# Clone the repo we want to merge into the slug directory
git clone $3 $2
# Smush the whole repo into a subdirectory, creates /e360-slug/e360-slug/*.*
cd $2
git filter-repo --to-subdirectory-filter $2
# Okay go back to (/root/wp-content)
cd ../$1
# Add /root/e360-slug as a remote called e360-slug
git remote add $2 ../$2
# Fetch and merge e360-slug
git fetch $2 --tags
git merge --allow-unrelated-histories --no-edit $2/trunk
# Move new repo into /root/wp-content/plugins/e360-slug
git mv $2 plugins/$2
# Print a status for us.
git status
# Clean up everything we did
echo 'cleaning up'
git remote rm $2
cd ..
rm -rf $2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment