Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [[ $# -lt 3 ]] ; then
- echo "Usage: merge-my-repos <sub_directory> <path_to_repo> <prefix_for_tags>"
- exit 1
- fi
- DIR=$1
- REPO=$2
- TAG_PREFIX=$3
- shopt -s extglob
- if [ -d "$DIR" ]; then
- echo "Specified Directory exits!"
- exit 1
- fi
- for old_tag in `git tag`
- do
- git tag -d $old_tag
- done
- git remote add other $REPO
- git fetch other --tags
- for old_tag in `git tag`
- do
- git tag "${TAG_PREFIX}${old_tag}" $old_tag
- git tag -d $old_tag
- done
- for branch in `git branch -r | grep -v HEAD | grep "other/" | cut -d '/' -f 2- `
- do
- git checkout -b temporaryBranch other/$branch
- rm -rf $DIR
- mkdir $DIR
- mv ./!($DIR) $DIR
- mv ./.!(git|idea||.) $DIR
- git add .
- git commit -q -m "Moved all files in branch '$branch' to subdirectory '$DIR'"
- git branch -D $branch
- git checkout -t origin/$branch
- if [[ $? -ne 0 ]] ; then
- git branch $branch
- git checkout $branch
- else
- git merge temporaryBranch --allow-unrelated-histories --commit --no-edit
- fi
- git branch -D temporaryBranch
- done
- git checkout master
- git remote remove other
- git push --all -u
- git push --tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement