1

Would appreciate your feedback on the following (I'm a Git beginner). I have a public repo on GitHub for my dissertation study's artifacts (mostly software, written in R). I'd like to adapt a third-party GitHub repo, containing LaTeX dissertation template (basically, I want to periodically sync with it, merging changes, which I want/need). I've created corresponding submodule for the manuscript within my main project directory structure. However, now I questioning whether this route is the best (optimal). My questions:

1) What is the proper workflow for the above-mentioned task?

2) Would is be an approximate equivalent to use a branch for the manuscript (within main directory structure) instead of a submodule? The reason I'm asking this is that it seems that the IDE I'm using for practically all my work on the project (RStudio) doesn't seem to currently support submodules (awaiting confirmation from the team), however it does support branches. If such replacement makes sense, would I still be able to sync my now branch for the template (mostly in a read-only mode, but it'd be great to be able to push some changes upstream, too).

Aleksandr Blekh
  • 2,300
  • 4
  • 25
  • 61

1 Answers1

1

If it doesn't support submodule, but you still need to push changes upstream, you could consider using subtree instead.
See an example at "Apply gradle file from different repository".

If you stick with submodules, note that a submodule can automatically follow a branch.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Appreciate your answer (upvoting and will accept pending clarifications below). If I'd stick to using submodules for manuscript, using command line, what is the proper way to sync downstream with corresponding GitHub repo? What is the safe way to deal with these issues: http://git-scm.com/book/en/Git-Tools-Submodules#Issues-with-Submodules? – Aleksandr Blekh Sep 12 '14 at 06:32
  • 1
    @AleksandrBlekh simply making sure that your index is clean when you update a submodule (ie: everything changes was added/committed/pushed *before* updating the submodule, and if changes there were, that the parent repo has also added/committed/pushed the changed gitink, as explained in the second part of http://stackoverflow.com/a/25562380/6309) – VonC Sep 12 '14 at 06:36
  • I see. An accidental update with files waiting for commit/push would remove the changes, right? Also, do I need to do `git submodule add -b master [URL to Git repo]` after I did simple `git submodule add`, or it's instead (if so, do I need to undo the former command)? Thank you! – Aleksandr Blekh Sep 12 '14 at 06:43
  • 1
    @AleksandrBlekh you can convert an existing submodule in order to make it follow a branch (no need to delete and redo the submodule defninition): http://stackoverflow.com/a/18799234/6309 – VonC Sep 12 '14 at 06:45
  • Sorry, during initial read somehow I missed that link in your answer. So, then syncing downstream is basically issuing command `git submodule update --remote` periodically (making sure the index is clean first). Correct? – Aleksandr Blekh Sep 12 '14 at 06:48
  • 1
    @AleksandrBlekh, yes it is the idea. Note: the link in my previous comment wasn't in my answer directly. – VonC Sep 12 '14 at 06:48
  • Great! Thank you so much for your amazing help! Accepting your answer. I also have a question or two, related to using `make` properly for my dissertation workflow. Would you be so kind to help with these, too? – Aleksandr Blekh Sep 12 '14 at 06:51
  • @AleksandrBlekh I am not as experienced in R and LaTeX, but I can certainly have a look. – VonC Sep 12 '14 at 06:52
  • Greatly appreciate it! Here are the questions, in chronological order (they're not specific to R/LaTeX, so no problem at all): 1) http://stackoverflow.com/q/23910056/2872891; 2) http://stackoverflow.com/q/23956295/2872891; 3) http://stackoverflow.com/q/24573413/2872891. – Aleksandr Blekh Sep 12 '14 at 07:00
  • Sorry to bother again. I just tried to test my new submodule repo, which you helped me with. I wanted to make sure that any changes I will make in that sub-directory will be pushed upstream to my main repo, not the original source ('master' branch of which I follow). I created a two-character text file in the submodule directory, expecting it to appear in my RStudio's Git panel. The directory name appeared, but it wouldn't allow me to select it for commit. Diff says: "Subproject commit -dirty". I've read your answer here: http://stackoverflow.com/a/4874323/2872891. (to be continued) – Aleksandr Blekh Sep 12 '14 at 10:59
  • (cont'd) I'd like to ask you to clarify the following. In the submodule setup, will I be able to maintain the third-party (system) part of that directory up-to-date by syncing with external repo and, at the same time, to be able to push my own (user) changes to my GitHub repo, of which the submodule directory is local part? – Aleksandr Blekh Sep 12 '14 at 11:04
  • 1
    @AleksandrBlekh I will check that this evening. A bit busy at the moment – VonC Sep 12 '14 at 11:08