Skip to content

Instantly share code, notes, and snippets.

@manishpathak99
Created December 31, 2015 02:30
Show Gist options
  • Save manishpathak99/898cfeb4b909eeea60a7 to your computer and use it in GitHub Desktop.
Save manishpathak99/898cfeb4b909eeea60a7 to your computer and use it in GitHub Desktop.
Script to copy GIT history from one repo to another newly created repo.
# Step 1
usage ()
{
echo 'This script is used to copy the code history of one repository to another repository'
echo 'Please provide the parameters as below'
echo 'Usage : Script <SOURCE_REPO_URL> <DST_REPO_URL> <source_repo_name> <dest_repo_name>'
exit
}
if [ "$#" -ne 4 ]
then
usage
fi
echo "The SOURCE_REPO_URL is $1"
echo "The DST_REPO_URL is $2"
echo "The source_repo_name is $3"
echo "The dest_repo_name is $4"
BASEDIR=$(dirname $0)
echo $BASEDIR
git clone $1
cd $3
echo `pwd`
# Step 2
git remote rm origin
# Step 3
mkdir $3
# Step 4
#
# NOTE: You can't actually do this command verbatim. You need to
# git mv each top-level file/dir individually and don't forget
# .* files like .gitignore, but DO NOT copy the .git directory.
mkdir temp
echo "Moving .git to temp Directory... `pwd`"
mv -v .git temp/
echo "Moving All files to $3 Directory..."
mv -v *.* $3/
mv -v temp/.git .
# Step 5
git commit -m "Prepare $3 to merge into $4"
cd ..
# Step 6
srcrepofilepath=`pwd`/$3
git clone $2
cd $4
echo "PWD -> `pwd`"
echo "srcrepofilepath -> $srcrepofilepath"
# Step 7
git remote add $3 $srcrepofilepath
#Here you might have to resolve the comflict. then you will need execute rebase continue.
#and run below steps
# Step 8
git pull $3 master
# Step 9
git remote rm $3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment