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

and want to have a new structure like this

# old repo

# new repo

This can be done super easy with only two commands (from

  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 -f master
  3. Optional: Clean up (e.g. clone the original repo again) and to set your configs in /.git/config again

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s