Go back to fan’s Miscellaneous Repository.

Git subtree

Search

Issue

Solution

How to sync both folders properly? Traditional option is submodule, do not use that, use subtree, which is a standard feature for git since v1.7.11.

Create subtree in existing repository

  1. There is some git repository: “C:/Users/fan/Documents/Dropbox (UH-ECON)/Project Emily Minority Survey/”
    • make sure the repository does has been synced, no uncommited changes
  2. Add remote git url for draft folder
    • git remote add github_draft :FanWangEcon/ChinaSchoolClosure.git
  3. Suppose folder Drafts_RR is not in the repository yet, create subtree under that
    • git subtree add –prefix=Drafts_RR/ github_draft master: pull from master branch of remote repo github_draft defined in step 2, add remote repo files to Drafts_RR folder
  4. now updates in github_draft repo are synced inside the github repo. but github_draft remains independently syncable with overleaf. So overleaf does not have to be synced to much larger non-tex folder.

Sync Subtree Changes with Folder and Sub folder.

  1. make some changes in subfolder
  2. sync with the github repo first, commit changes in the master folder first.
  3. sync with subtre subfolder
    • cd “C:/Users/fan/Documents/Dropbox (UH-ECON)/Project Emily Minority Survey/”
    • git subtree push –prefix=Drafts_RR github_draft master

Commands Together


# Project git folder in dropbox
cd "C:/Users/fan/Documents/Dropbox (UH-ECON)/Project Emily Minority Survey/Drafts_RR"

# Add new paper draft remote url to project git remote urls
# github main is project repo url, github_draft is overleaf synced folder
git remote -v
git remote add github_draft git@github.com:FanWangEcon/ChinaSchoolClosure.git
git remote -v

# Add subtree, Drafts_RR should not exist yet
git subtree add --prefix=Drafts_RR github_draft


git subtree add --prefix "C:/Users/fan/Documents/Dropbox (UH-ECON)/Project Emily Minority Survey/Drafts_RR" git@github.com:FanWangEcon/ChinaSchoolClosure.git master --squash

git subtree split --prefix=Drafts_RR/ -b ChinaSchoolClosure
Do not use submodule

Console outputs

 $ git subtree add --prefix=Drafts_RR/ github_draft master
 git fetch github_draft master
 Enter passphrase for key '/c/Users/fan/.ssh/id_rsa':
 warning: no common commits
 remote: Enumerating objects: 235, done.
 remote: Counting objects: 100% (235/235), done.
 remote: Compressing objects: 100% (177/177), done.
 remote: Total 235 (delta 110), reused 133 (delta 50), pack-reused 0
 Receiving objects: 100% (235/235), 3.02 MiB | 3.58 MiB/s, done.
 Resolving deltas: 100% (110/110), done.
 From github.com:FanWangEcon/ChinaSchoolClosure
  * branch            master     -> FETCH_HEAD
  * [new branch]      master     -> github_draft/master
 Added dir 'Drafts_RR'
 fan@LAPTOP-55QHS6DU MINGW64 ~/Documents/Dropbox (UH-ECON)/Project Emily Minority Survey (master)
 $ ls
  Code/         Drafts/                  Images/                           notes.md        'Possible Questions and Answers.docx'   > andbox/                                  Tables/
  CodeEdccRR/   Drafts_RR/               Log/                              onenote1.pdf     presentation/                          > choolConsolidation_main_sexHan_wlt.pdf  'Tables Old'/
  comments/    'eth disparities irb'/   'Model Variables Graph Factory'/   onenote2.pdf    'R&R comments.docx'                     choolConsolidationDraft_V1.pdf
  Data/         Feedback/               'Notes and drafts, language'/      Planning.xmind   README.md                              Submissions/
  desktop.ini  'Government Documents'/  'Notes and Papers'/                policies/       'Reference papers'/                     summer2014visitors/

 fan@LAPTOP-55QHS6DU MINGW64 ~/Documents/Dropbox (UH-ECON)/Project Emily Minority Survey (master)
 $ ls Drafts_RR
 _bib/  _fig/  _tab/  draft_main.pdf  draft_main.tex  fragments/  preamble_main.tex  sections/