Skip to content

Instantly share code, notes, and snippets.

@paulius-sladkevicius
Forked from JackLeo/git_combine
Last active August 29, 2015 14:07
Show Gist options
  • Save paulius-sladkevicius/51707055156c6b9a7544 to your computer and use it in GitHub Desktop.
Save paulius-sladkevicius/51707055156c6b9a7544 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ ! $# -gt 2 ]; then
echo "Usage: ./git_combine.sh new_repo_folder repo_folder repo_folder ..."
exit
fi
if [ ! -d $1 ]; then
mkdir $1
fi
if [ ! -d $1/.git ]; then
cd $1
git init
fi
new_repo=$1
shift
while test $# -gt 0
do
if [ ! -d $1 ]; then
echo "$1 does not exist"
exit
fi
if [ ! -d $1/.git ]; then
echo "$1 is not a git repository"
exit
fi
echo "$(tput setaf 2)Moving $1$(tput sgr0)"
cd $1
git fetch --all
git checkout master
git pull origin master
git remote rm origin
for f in `ls`; do
if [ ! -d $1 ]; then
mkdir $1
fi
git mv $f $1/
done
git commit -m "Prepare to move $1 to $new_repo"
cd ../$new_repo
echo "$(tput setaf 2)Adding remotes$(tput sgr0)"
git remote add $1 ../$1
git pull $1 master
git remote rm $1
cd ..
rm -rf $1
shift
done
echo "$(tput setaf 2)Done$(tput sgr0)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment