4

I have a nested git repository structure, as below:

outer_repository/
|-- outer_dummy_file
|-- .git 
`-- inner_repository
    |-- .git
    `-- inner_dummy_file

Is it possible to make inner_repository/.git versioned with the outer repository?

Motivation:

I'm making a structure for new projects with cookiecutter. Every newly started project will have a predefined set of files and tools to begin with. One of the requirements for the automated versioning system if for the new project to be versioned with git and having an initial commit. The inner_repository is a structure for the new projects.

TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
  • 1
    have you looked at [`git submodule`](https://git-scm.com/docs/git-submodule) or [`git subtree`](https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844#.9sx8mzxcl)? – Sukima Jul 24 '16 at 20:50

2 Answers2

9

It is possible to achieve this without the need to do the git acrobatics. Cookiecutter provides an option to run post generation hooks. This allows creation of the git repository to happen on project creation.

I've added the following in my cookiecutter repository:

hooks/
`-- post_gen_project.py

where post_gen_project.py is:

import subprocess

subprocess.call(['git', 'init'])
subprocess.call(['git', 'add', '*'])
subprocess.call(['git', 'commit', '-m', 'Initial commit'])
TheMeaningfulEngineer
  • 15,679
  • 27
  • 85
  • 143
0

Just create a versioned template project (with initial files etc.), and let new projects be a fork of the template project? Versioning the .git content sounds like a bad idea.

λuser
  • 893
  • 8
  • 14
  • 1
    In general it is. This is a specific question on generating a cookiecutter project that is already a git repo. As to your suggestion, if I would to clone a project, all the directory naming would remain the same while with cookiecutter I can define project name and other project specific attributes that will be automatically assigned upon project creation. "Assigned" means that template variables in files and filenames will be replaced with the appropriate strings for that project. – TheMeaningfulEngineer Jul 24 '16 at 21:41