Skip to content

Instantly share code, notes, and snippets.

@manojLondhe
Forked from alghanmi/import_git2git.sh
Created January 6, 2020 06:48
Show Gist options
  • Save manojLondhe/d98ed2f70ba063bd7a9cfaf9d5bced3d to your computer and use it in GitHub Desktop.
Save manojLondhe/d98ed2f70ba063bd7a9cfaf9d5bced3d to your computer and use it in GitHub Desktop.
Import an existing git repository (A) into another (B)
#!/bin/sh
##
## Import an existing git repository (A) into another (B)
##
## Reference: http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
##
REPO_A="<git repo A url>"
REPO_A_DIR="<directory 1>"
REPO_B="<git repo B url>"
# Prep Repo A
git clone $REPO_A repoA
cd repoA
git remote rm origin
mkdir $REPO_A_DIR
git mv * $REPO_A_DIR
git add .
git status # do a sanity check
git commit
cd ..
# Prep Repo B
git clone $REPO_B repoB
cd repoB
git remote add repoA_branch ../repoA
git pull repoA_branch master
git remote rm repoA_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment