Skip to content

Instantly share code, notes, and snippets.

@alghanmi
Last active January 6, 2020 06:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save alghanmi/4064371 to your computer and use it in GitHub Desktop.
Save alghanmi/4064371 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