-
-
Save paulius-sladkevicius/51707055156c6b9a7544 to your computer and use it in GitHub Desktop.
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 | |
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