Created
March 18, 2014 15:03
-
-
Save JackLeo/9621843 to your computer and use it in GitHub Desktop.
simple and crude script to combine few repos to one on master branch
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
-gt is greater than$1 and I just run while statement checking if $ # has any more arguments. $# is a number of total arguments given
$(tput setaf 2)Done$ (tput sgr0) thats for colors
-d checks if it's directory
$1..$N is list of arguments being $0 git_combine.sh and shift does pop of $N array so after first shift $2 becomes