move a folder to other git repo

Engineering Sep 19, 2017

To move a sub-directory/folder to other git repo. Let's leave the usual working directory as is, and create new directory for this experiments.

Go to new directory, let's say ~/parallel-universe.

sun/
  fossil/
      dinousar
      tardigrades
  chemicals/
  energy/
  .git/
earth/

Steps:

  cd ~/parallel-universe/
  git clone [email protected]:universe/sun.git
  cd sun/ 
  git remote rm origin
  git filter-branch --subdirectory-filter fossil -- --all
  #Folder `sun` should now contain only `.git` and `fossil/`
  
  cd ~/parallel-universe/
  mv sun/ earth/
  cd earth/
  git remote add origin [email protected]:universe/earth.git
  git pull origin master --allow-unrelated-histories
  git push origin master

Now you can remove the folder fossil from sun if want to.

Srujan

You should go to about section on this site.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.