35

I have a git repo which have following folders:

 _includes/
 _layouts/
 _plugins/
 _posts/
 _site/

_site folder is added in the .gitignore file.

Now can I have a git repo inside _site folder with different remote repo for push and pull? Will there be any conflict?

I have studied git submodules but I think it would be a overkill in my case, if the above stated method can work.

Andrew-Dufresne
  • 5,464
  • 7
  • 46
  • 68
  • I'd be surprised if it works, and even if it does you can have surprises as it's not intended/designed to work. Git submodules are not overkill, just take some time to understand the basics :) – CharlesB Apr 18 '12 at 08:16
  • Also by staying out of submodules, you loose the ability to tell the main repo what revision `_site` is at – CharlesB Apr 18 '12 at 08:18
  • 2
    "you loose the ability to tell the main repo what revision _site is at" But `_site` is in `.gitignore` so main repo already does not know anything about the `_site` folder. – Andrew-Dufresne Apr 18 '12 at 08:45
  • Sure, but that's already not ideal :) – CharlesB Apr 18 '12 at 08:48
  • For what it's worth, there is at least one (strange but valid) use case for doing this: If you want to track your home directory dotfiles in git. This is how I maintain and replicate my configuration across different machines, without having to remember to move the dotfiles to/from the repo every time I edit them. My home dir _is itself a git repo_, so I can simply push/pull and all my machines keep the latest configuration. _ALL_ files that aren't application config files get put in my gitignores, including all my development repos. – Neil Traft Oct 18 '21 at 16:38

2 Answers2

23

I think it should work. For main repo, _site folder does not exists. So what you have inside it doesn't matter. When you cd into _site you will be on that independent repo.

Juan G. Hurtado
  • 2,057
  • 16
  • 25
  • 19
    However, keep in mind that it might lead to some issues. One of the problems is that `git clean -dfx` in the outer repo will remove the nested repo. Hence, the user must be careful. Maybe it would be better to symlink the folder. In case of running `git clean`, the symlink will be removed, and the nested repo will remain intact. – Yamaneko Apr 17 '14 at 04:42
11

Yes - I just tried it. Here is my command line session:

$ mkdir temp
$ cd temp
$ git init 
Initialized empty Git repository in /Users/mpdaugherty/temp/.git/
$ git add .
$ git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
$ echo 'ignore' >> .gitignore
$ git add .
$ git commit -a -m 'first commit'
[master (root-commit) 17d293c] first commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
$ mkdir ignore
$ git status
# On branch master
nothing to commit (working directory clean)
$ cd ignore
$ git init .
Initialized empty Git repository in /Users/mpdaugherty/temp/ignore/.git/
$ echo 'Some text' > somefile.txt
$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   somefile.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add .
$ git commit -a -m 'initial commit'
[master (root-commit) 107f980] initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 somefile.txt
$ cd ..
$ git status
# On branch master
nothing to commit (working directory clean)
mpdaugherty
  • 1,118
  • 8
  • 19