0

I am wanting to version control my entire 'CLIENT' folder which includes everything for my clients such as fonts, stock images, designs, print files etc. Some of these files are very large so there is no way I could upload these to a remote repo.

On the other hand, I would like to upload their website to a remote repo for when another developer works on the site.

On this basis I am thinking of creating a repo for the main client folder and submodule for the website project. Unless there is a better way of doing things?

For reference, my project file structure is as follows:

~/Documents/Clients/Client/Projects/Website/5-Website

Client = Main project folder 5-Website = Website Project

I'm opening my main project folder in Terminal (MacOS) and initialising git using the following code

cd ~/Documents/Clients/Client && git init && git config --global user.email 'name@email.com' && git config --global user.name 'Full Name' && git add . && git commit -m 'initial commit, added all files'

It's working perfect up till this point and here's where it does wrong.

I then (while I am still in the client folder) type into Terminal

git submodule add --name website ~/Documents/Clients/TEMPLATE/projects/Website/5-Website

To try to add my submodule but I get the following error:

fatal: repository '/Users/User/Documents/Clients/CLIENT/projects/Website/5-WEBSITE' does not exist
fatal: clone of '/Users/User/Documents/Clients/CLIENT/projects/Website/5-WEBSITE' into submodule path '/Users/User/Documents/Clients/CLIENT/5-WEBSITE' failed

If you notice the last part of the error message, it misses out part of the folder url just 5-website.

What am I doing wrong?

Juan-man
  • 436
  • 4
  • 13
  • Is `5-Website` directory a git repository ? – Saurabh P Bhandari Mar 31 '20 at 15:16
  • That would be a git repository for the clients website. I thought it best that the website have it's own repo. – Juan-man Mar 31 '20 at 18:19
  • Did the below answer help? – Saurabh P Bhandari Apr 01 '20 at 01:15
  • I'm still working on it so I've not marked it as answered yet. One thing I have noticed is 'git add submodule' should be 'git submodule add'. I've managed to get it working but it clones my submodule folder into my projects folder. I want to leave the submodule folder where it is without cloning it. `Is this correct? I'm now thinking can I not just use git init in my project folder and git init in my web folder and then use .gitignore to not look at the web project folder? – Juan-man Apr 02 '20 at 12:31
  • I have fixed the command. If you want leave the submodule folder as it is (no cloning) then you can do this `git submodule add --name website -- path/to/website/project path/to/website/project`, The first path means `` and second path is path to where it should be cloned (since it already exists, git won't clone again) – Saurabh P Bhandari Apr 02 '20 at 13:34

1 Answers1

0

By executing this command

cd ~/Documents/Clients/Client && git init && git config --global user.email 'name@email.com' && git config --global user.name 'Full Name' && git add . && git commit -m 'initial commit, added all files'

you have already added the Website project as a normal sub-directory in the main repository Client.

One way to deal with this would be to,

  • Delete .git directory in the main repository and start over (see note below before performing this)
  • First make the website project a git repository

      # Make website project a git repo
      cd /path/to/website/project
      git init
    
      # Add all files for staging
      git add .
    
      # Commit the changes
      git commit -m "initial commit for website project"
    
      # Push to remote
    
  • Make the website project which is now a git repository a submodule of client project

      # Make client project a git repo
      cd /path/to/client/project
      git init
    
      # Add website project as submodule
      git submodule add --name website /path/to/website/project
    
      # Add all the files in client project for staging
      git add .
    
      # Commit the changes for client project
      git commit -m "initial commit for client project"
    

Please note that this assumes that you have not done any changes beyond the initial commit as by deleting the .git directory you lose all the commits and history. If you have made new commits since the initial commit then see this.

Also this assumes that you want to create a local git submodule. If you were to push the website project to a remote repo, you could replace this /path/to/website/project with <remote-repo-link> in the submodule add step.

Saurabh P Bhandari
  • 6,014
  • 1
  • 19
  • 50
  • Thank you for your replay. So just to make sure I have this correct, I have to do ``` git init ``` in my website directory first then push that to the remote repo. Once that's done, go to my main project folder (Client) and then do ``` git init ``` for that directory. Then add the submodule? – Juan-man Mar 31 '20 at 18:22
  • @Juan-man yes but be sure of what you are doing if you have already committed some changes – Saurabh P Bhandari Mar 31 '20 at 18:39