0

I have a specific situation and i didn't found the answer on stack that matches it.
I have a root_project which is base app directory, synchronized with it's remote repo.

Now i have a folder in it, which is named oscar. I've previously downloaded zipped oscar and copied it into my root_project, after i've customised it in places i needed.
After that i have noticed that i get into troubles if i need to get updates from remote oscar once those are made up.

The basic idea is to use git submodule but really can't figure out how to adapt it to my necesities as i don't want to crash my project and repo on experimenting.

Also a specific part is that i need only src/oscar from oscar repo, that is actually in my root_project and to make it possible to merge with my changes in local oscar folder, without loosing the things i've already done locally.

I would appreciate any help and suggestions on how to use correctly git submodule in current circumstances, also if possible wanna see the steps i must do on achieving desired results

Iulian Pinzaru
  • 400
  • 3
  • 10

1 Answers1

1

[...] as i don't want to crash my project and repo on experimenting.

First of all, you should not be afraid to try things in your local repository. As long as you stay on your local copy and do not publish experimental changes, you can always just delete the whole thing and clone it again from your remote. It is a very good way to learn stuff if you just try things out, especially when you break everything underway. Do not hesitate to do so!

To answer your question: I assume oscar exists as a remote repository. Git submodules are indeed a good way to manage a subrepository that you need to update occasionally. You can find good documentation on how to use submodules here. It will be easier if you clone oscar directly from the remote via git submodule add instead of downloading and extracting a zip file first. This newly cloned submodule will of course not contain your local changes to oscar, but you can easily import them by following the steps described here.

Also a specific part is that i need only src/oscar from oscar repo, that is actually in my root_project and to make it possible to merge with my changes in local oscar folder, without loosing the things i've already done locally.

I do not understand this part. Do you only want to add a subfolder of oscaras a submodule?

EDIT: So you want your submodule to conatin only a subfolder of the oscar repository. You can do this after cloning the whole repository (via git submodule add) with

git filter-branch --prune-empty --subdirectory-filter FOLDER-NAME  BRANCH-NAME 

The process is described here, although only point 5 is of interest for you. Note that you have to do this inside your submodule, i.e. you have to cd into your submodule folder.

Community
  • 1
  • 1
kowsky
  • 12,647
  • 2
  • 28
  • 41
  • Thx for suggestion, yes i want the ``src/oscar`` folder only, because the oscar repo includes also sandbox and other stuff – Iulian Pinzaru Apr 19 '17 at 11:45
  • As you can see here https://github.com/django-oscar/django-oscar the oscar git repo delivers the sandbox and other things i don't need to be synchronized with. I need src/oscar only to be merged with mine same folder in ``root_project``. Is it possible to do that the way you mentioned before ?? – Iulian Pinzaru Apr 19 '17 at 11:50
  • See my edit for details on how to extract a subfolder from the cloned submodule. – kowsky Apr 19 '17 at 11:58
  • Thx for answering and paying attention on details, i guess this is what i need. I'll try this tomorrow and tell you if it worked :) – Iulian Pinzaru Apr 19 '17 at 12:33