Home > Software engineering >  How to make several folders a single project in Git?
How to make several folders a single project in Git?

Time:11-10

I am following a tutorial on Udemy to learn Angular, the instructor provided the code, but each lesson is a new project in a new folder. I would like to merge all the folders into a single repository, so that each folder is a commit. How could I do that?.

This is a screenshot of a section of the course. As I said, I would like each of those folders to be a commit, because the content of each one is almost the same. And it would be easier for me to hit "git checkout" every time I go to a new lesson, than to open each folder, install the dependencies and start a new server.

enter image description here

The only solution I've come up with so far is to go to the beginning of the project, hit commit, then delete all the files and paste the contents of the next lesson, hit commit again, and so on, but it would be very time consuming.

CodePudding user response:

How about consolidating them into a single one?

At the same level where you have all those different directories with numbers, create a new one to join them all together:

git init todo-junto # I know he speaks spanish so it's fine ;-)
cd todo-junto
for i in 15 17 18 19 20 21; do # all the separate projects
    git remote add tarea$i ../$i # tarea15 for 15, tarea17 for 17
    git fetch tarea$i # get to see the branches in that repo.... we will _copy_ main
    git branch tarea_$i tarea$i/main # create local branch tarea_15 for remote tarea15/main and so on
    # now we can remove the remote as we have the local branch
    git remote remove tarea$i
done

Now you have separate btranches in a single repo (tarea_15, tarea_17 and so on).

CodePudding user response:

You can create a repository in any directory using git init. So just run that command from the folder that contains all of the other folders to have a single repository with all examples in it.

If you want all the folders put into the new repo as individual commits, instead of all at once, you would need to do that 1 folder at a time (git init in a new folder, then 1 by 1 copy in a lesson-folder and stage/commit the changes).

I am not aware of a way to automate all the commits for each folder other than a shell script, but I really don't see value it would provide to do so.

  •  Tags:  
  • git
  • Related