Home > database >  Uploading a django project to a github repo
Uploading a django project to a github repo

Time:08-03

I am relatively new to github and I am still trying to take my django application into production using a github repository. The problem is that for some reason, github has refused to commit a certain folder to the main branch. When I try to commit the changes I get the following message:

On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        blog/

nothing added to commit but untracked files present (use "git add" to track) 

So I assume its telling me that there are some untracked files within the blog folder but when I try to add the folder, I get the following error:

warning: adding embedded git repository: blog
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of    
hint: the embedded repository and will not know how to obtain it.        
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> blog
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached blog
hint: 
hint: See "git help submodule" for more information.

It appears, its treating it as a github repository, even though it is a folder within my project. So here is my file system:

blog---(main project folder with the settings.py, this is the folder that is refusing to commit)
|
media
|
posts
|
static
|
templates
|
manage.py
|
some other system files

What could be the issue? is it that I might have previously uploaded a repo with the same name and linked it to the same project file, but later deleted it. I am at a loss. Any help would be appreciated

CodePudding user response:

warning: adding embedded git repository: blog

It appears, its treating it as a github repository ...

It is indeed a Git repository. (GitHub is a commercial web site that, among other things they do, includes the hosting of Git repositories.)

even though it is a folder within my project

The blog folder is the working tree for this other Git repository.

A Git repository cannot actually contain another Git repository. Git's "hint" messages here are poor quality, but are correct: your "outer" repository is going to list the other repository as something that someone should clone, rather than actually contain the "inner" repository. But to list this correctly requires that you use git submodule add. If you allow things to proceed as they are, you'll get a broken submodule, or what I like to call a "half-assed" submodule. Git calls what it's going to store a gitlink and this is only half of a real submodule: the other half are instructions that Git needs later to clone the other Git repository.

If you wish to use submodules—and this is often a bad idea: people call them sob-modules with good reason—use git submodule add. If you don't wish to use submodules, make sure you aren't adding the working tree of a Git repository.

To make the blog folder not be the working tree of a Git repository, move the entire Git repository—including the working tree—somewhere else, make a new blog folder, and copy into that blog folder the files and sub-folders you'd like to put into your regular Git repository. (Note that blog currently contains a hidden folder named .git, which in turn contains the main repository databases and other ancillary control files for this second Git repository.)

To make the blog folder a proper submodule, use git rm --cached blog, as the hint says, then use git submodule add, as the hint says. Read up on sobmodules, er, I mean, submodules first.

  • Related