Categories
Development

Move .git to the parent directory

During development, we follow a specific file and folder structure. It’s common that things change during development. And in some cases, it’s necessary to move .git to the parent directory. This post shows how to achieve that.

When I started developing WordPress plugins, I’ve only pushed them to the plugin repository using SVN. Later, I started pushing them to GitHub as well to enable others to review and to contribute to my plugins. The plugins in the WordPress.org repository using the following structure:

plugin-slug
|-- assets/
|-- branches/
|-- tags/
|-- trunk/

Initially, I’ve only tracked and pushed the content of trunk to GitHub. This was the file and folder structure of my plugin:

plugin-slug
|-- assets/
|-- branches/
|-- tags/
|-- trunk/
     |-- .git/

Recently, I learned how to use Travis CI. Thus, I added all the needed files to the root folder of my plugin. This lead to the following structure:

plugin-slug
|-- assets/
|-- branches/
|-- tags/
|-- trunk/
     |-- .git/
|-- .eslintrc
|-- .travis.yml
|-- composer.json
|-- package.json
|-- phpcs.xml.dist

Move .git to the parent directory

  1. Rename the folder trunk to trunk_old
  2. Create the folder trunk within trunk_old and move all files from the trunk_old folder to trunk
  3. Move all other files and folders into trunk_old
  4. Move all files and folders from trunk_old into the root folder
  5. Delete the folder _trunk
  6. Commit your changes

This is the structure of my plugin after the change:

plugin-slug
|-- assets/
|-- branches/
|-- tags/
|-- trunk/
|-- .git/
|-- .eslintrc
|-- .travis.yml
|-- composer.json
|-- package.json
|-- phpcs.xml.dist

Leave a Reply