1

I'm trying to add multiple project in one repository from Github desktop from Macbook but not able to do it.

While trying to commit it show me this error Failed to add file subfoldername/ to index.

I have tried to figure out and read some answers but not work from terminal as well. Other one i have tried from here.

I have added all my folder in one folder main repository then trying to add.

Is there any other way to do it from Github desktop ?

Or am i missing something. Somebody have idea please suggest something.

Thanks in advance. I'll appreciated if somebody give me some better solution.

2
  • What do you mean multiple projects in one repository? Commented Mar 13, 2017 at 4:16
  • @llion Thanks for reply, i need to add 3 projects in same repository but when i trying to do it show me an error. Commented Mar 13, 2017 at 4:42

2 Answers 2

11

Try, from the command line, in a fresh clone of your main repo (assuming your multiple projects are all individual git repositories):

 git clone /url/of/main/repo cd repo git submodule add /url/of/project1 git submodule add /url/of/project2 git submodule add /url/of/project3 git commit -m "Add multiple projects" git push 

This uses git submodules in order to record references to those projects in your main repository.

Sign up to request clarification or add additional context in comments.

4 Comments

folder is created and it is showing in github but no data is showing inside folder.
@Saveen That is expected. do a git submodule update --init and the content will show up
@Saveen And later on, when you clone that repo, do a git clone --recursive: that will clone and checkout the submodules as well as your main repo.
@Saveen Note that, on the remote side, those folders would appear empty: they are gitlink: stackoverflow.com/a/25479758/6309
1

Apologies as it's not that concrete solution to it but it does the job, what I tried is I had a situation where for some reason I had to add all the projects to one repository only so I followed the following steps :

  1. Create a new repository with the main branch (Keep it Empty)
  2. Create a branch from Main (Empty) with the respective project name (Create as many as branches you want with the respective projects you have)
  3. Then Checkout to that branch with the command:

$git checkout -b <branch_name>

  1. If the origin is already there then remove it first then add the newly created remote origin with the following commands:

$ git remote rm origin (To remove remote origin)

$ git remote add origin https://github.com//<REPO_NAME>.git

  1. For authorization of the operation you need to use the following command:

$ git remote set-url origin <Access_Token>@github.com//<REPO_NAME>.git

  1. Now, you can push the code and files to the branch directly by the following command:

$ git push -u -f origin <branch_name>

  1. If the above command is throwing an error then try first adding the files by the following command and then try step 6 again.

$ git add .

This worked for me, as whenever I want to change/pull something in any project I just clone a specific branch make changes in it and then push the changes to that specific branch only. This way you can have multiple projects under one repo. I tried this solution by myself only to bypass the tricky way of Orphan branches or having multiple Repos.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.