2 Git Combine Repos
tengel edited this page 2024-09-05 08:27:27 -05:00

Combine repos in git

# Create a new empty repo and clone it ("origin")
git clone git@gitlab.com:${myname}/newproject.git
cd newproject/

# Do basic required config if needed
git config user.name ${myname}
git config user.email ${myemail}

# Add each remote repo as a subdir (prefix) including commit history
git subtree add --prefix=oldproject_1 \
  git@gitlab.com:${myname}/oldproject_1.git master
git subtree add --prefix=oldproject_2 \
  git@gitlab.com:${myname}/oldproject_2.git master

# Do any cleanup needed - for example getting rid of a submodule
git rm oldproject_1/somegitsubmodule
git rm oldproject_1/.gitmodules
git commit -m "remove stale submodule" \
  oldproject_1/.gitmodules \
  oldproject_1/somegitsubmodule

# Commit the results back up to your new project
git push origin master