1

I have a folder with multiple subfolders that I would like to upload to Git. I would like to be able to edit my code from multiple computers, without having to worry about which one I'm on. My folders are set up something like this:

top-folder\week1
top-folder\week2
top-folder\week3
top-folder\week4

Some of the subfolders have subfolders of their own that have already been set up as repos:

top-folder\week3\exercise2[cloned repo]
top-folder\week3\exercise4[cloned repo]

Is it possible to set up "top-folder" as a repo, so that I can access all the code files in the subfolders?

  • 3
    git doesn't track directories at all -- it only tracks files. When you add a file, it considers the directory that file is in to implicitly exist. – Charles Duffy Mar 23 '18 at 17:53
  • That said -- yes, of course, you can do a `git init` in your directory named `top-folder`. Keep in mind that the Linux kernel -- which git was created for -- has a very deep directory structure, so it wouldn't have been fit for even its initial use case if it couldn't handle directory contents. – Charles Duffy Mar 23 '18 at 17:54
  • OR just copy the main folder and paste it and all its content into the Git repo. – Ryan Wilson Mar 23 '18 at 17:54
  • 1
    Possible duplicate of [How to commit a directory into a git repository?](https://stackoverflow.com/questions/1573883/how-to-commit-a-directory-into-a-git-repository) – Charles Duffy Mar 23 '18 at 17:55
  • Also related: [Recursively add the entire folder to repository](https://stackoverflow.com/questions/17743549/recursively-add-the-entire-folder-to-a-repository); [How do I add files and folders into GitHub repos?](https://stackoverflow.com/questions/8775850/how-do-i-add-files-and-folders-into-github-repos); [How do I add the src directory instead of the original files?](https://stackoverflow.com/questions/40622813/how-do-i-add-the-src-directory-instead-of-the-individual-files) – Charles Duffy Mar 23 '18 at 18:18
  • Similar, but not quite a duplicate. All my folders contain files. I did use git init in the existing top-folder, as well as --all and --force, but all subfolders that were already set up as cloned repos just show up with a different folder icon that can't be opened. – Greengecko19 Mar 23 '18 at 18:19

2 Answers2

1

You can make your subrepositories submodules. If you don't want to treat them as submodules you have to remove or rename .git/ subdirectories in subrepositories (having backup, of course).

phd
  • 82,685
  • 13
  • 120
  • 165
0

Yes! Of course (given the folders are not empty). If your folders are empty consider adding an empty file to the empty folder to check it into git.

cd top-folder
git init

You are turning top-folder to a git repository.

git add . 

You now added every file in the directory tree to git. Alternatively (depending on you shell ) something like `git add **/excersise* will work.

git commit ... 

Commit and you have everything checked in.

If you have submodules (git repositories inside repositories) check here

Amanuel Nega
  • 1,899
  • 1
  • 24
  • 42
  • In [How to Answer](https://stackoverflow.com/help/how-to-answer), note the section "Answer Well-Asked Questions", and therein the bullet point regarding questions which "have already been asked and answered many times before". – Charles Duffy Mar 23 '18 at 18:16
  • Except that those answers don't answer what to do with subrepositories. – phd Mar 23 '18 at 19:36