Move subfolder into new GitHub repo

Sometimes it happens that you want to outsource a sub directory from your GitHub repository to a separate new repository.

e.g. you have a structure like

# github repo
/electrobabe
  /chefbabe
    /app
  /papierwahl

and want to have a new structure like this

# old repo
/electrobabe
  /papierwahl

# new repo
/chefbabe
  /app

This can be done super easy with only two commands (from help.github.com):

  1. in your original directory
    cd electrobabe
    git filter-branch --prune-empty --subdirectory-filter 
     chefbabe master

    The directory electrobabe now only contains the files of chefbabe.

  2. Push to your already created new empty repo:
    git push git@github.com:chefbabe.git -f master
  3. Optional: Clean up (e.g. clone the original repo again) and to set your configs in /.git/config again
Advertisement