Skip to content

Instantly share code, notes, and snippets.

@dummys
Forked from tswaters/git-subdirectory-tracking.md
Created November 14, 2019 09:35
Show Gist options
  • Select an option

  • Save dummys/83160d9b159aa726dcf423d0061f810c to your computer and use it in GitHub Desktop.

Select an option

Save dummys/83160d9b159aa726dcf423d0061f810c to your computer and use it in GitHub Desktop.

Revisions

  1. @tswaters tswaters revised this gist Jan 24, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions git-subdirectory-tracking.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ git remote add -f jsdoc-upstream [email protected]:jsdoc3/jsdoc.git
    git checkout -b upstream/jsdoc jsdoc-upstream/master

    # split off subdir of tracking branch into separate branch
    git subtree split --squash --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc
    git subtree split -q --squash --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc

    # add separate branch as subdirectory on master.
    git checkout master
    @@ -31,11 +31,11 @@ git checkout upstream/jsdoc
    git pull jsdoc-upstream/master

    # update the separate branch with changes from upstream
    git subtree split --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc
    git subtree split -q --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc

    # switch back to master and use subtree merge to update the subdirectory
    git checkout master
    git subtree merge --prefix=templates/default --squash merging/jsdoc
    git subtree merge -q --prefix=templates/default --squash merging/jsdoc
    ```

    May I never have to google this again. I still haven't tried merging upstream yet, guess I'll cross that bridge when I get to it.
  2. @tswaters tswaters revised this gist Jan 24, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-subdirectory-tracking.md
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@ git subtree add --prefix=jsdoc-template --squash merging/jsdoc
    ```

    ## Fetching upstram
    ```
    ```sh
    # switch back to tracking branch, fetch & rebase.
    git checkout upstream/jsdoc
    git pull jsdoc-upstream/master
  3. @tswaters tswaters revised this gist Jan 24, 2015. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion git-subdirectory-tracking.md
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,8 @@ In this particular case, I'm interested in bringing in the 'default' template of

    After much struggling with git, subtree and git-subtree, I ended up finding this http://archive.h2ik.co/2011/03/having-fun-with-git-subtree/ -- it basically sets up separate branches from tracking remote, the particular sub-directory, and uses git subtree contrib module to pull it all togther. Following are the commands, modified for my use case :

    ## Initial setup...

    ```sh
    # add jsdoc remote, create new tracking branch,
    git remote add -f jsdoc-upstream [email protected]:jsdoc3/jsdoc.git
    @@ -20,7 +22,10 @@ git subtree split --squash --prefix=templates/default --annotate="[jsdoc] " --re
    # add separate branch as subdirectory on master.
    git checkout master
    git subtree add --prefix=jsdoc-template --squash merging/jsdoc
    ```

    ## Fetching upstram
    ```
    # switch back to tracking branch, fetch & rebase.
    git checkout upstream/jsdoc
    git pull jsdoc-upstream/master
    @@ -33,4 +38,4 @@ git checkout master
    git subtree merge --prefix=templates/default --squash merging/jsdoc
    ```

    May I never have to google this again.
    May I never have to google this again. I still haven't tried merging upstream yet, guess I'll cross that bridge when I get to it.
  4. @tswaters tswaters revised this gist Jan 24, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion git-subdirectory-tracking.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ git checkout upstream/jsdoc
    git pull jsdoc-upstream/master

    # update the separate branch with changes from upstream
    git subtree split --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc`
    git subtree split --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc

    # switch back to master and use subtree merge to update the subdirectory
    git checkout master
  5. @tswaters tswaters revised this gist Jan 24, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions git-subdirectory-tracking.md
    Original file line number Diff line number Diff line change
    @@ -11,12 +11,10 @@ After much struggling with git, subtree and git-subtree, I ended up finding this

    ```sh
    # add jsdoc remote, create new tracking branch,

    git remote add -f jsdoc-upstream [email protected]:jsdoc3/jsdoc.git
    git checkout -b upstream/jsdoc jsdoc-upstream/master

    # split off subdir of tracking branch into separate branch

    git subtree split --squash --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc

    # add separate branch as subdirectory on master.
  6. @tswaters tswaters renamed this gist Jan 24, 2015. 1 changed file with 0 additions and 0 deletions.
  7. @tswaters tswaters renamed this gist Jan 24, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. @tswaters tswaters created this gist Jan 24, 2015.
    38 changes: 38 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    This is way more complicated than it should be. The following conditions need to be met :

    1. need to be able to track and merge in upstream changes
    2. don't want remote commit messages in master
    3. only interested in sub-directory of another repo
    4. needs to go in a subdirectory in my repo.

    In this particular case, I'm interested in bringing in the 'default' template of jsdoc as a sub-directory in my project so I could potentially make changes to the markup it genereates while also being able to update from upstream if there are changes. Ideally their template should be a separate repo added to jsdoc via a submodule -- this way I could fork it and things would be much easier.... but, it is what it is.

    After much struggling with git, subtree and git-subtree, I ended up finding this http://archive.h2ik.co/2011/03/having-fun-with-git-subtree/ -- it basically sets up separate branches from tracking remote, the particular sub-directory, and uses git subtree contrib module to pull it all togther. Following are the commands, modified for my use case :

    ```sh
    # add jsdoc remote, create new tracking branch,

    git remote add -f jsdoc-upstream [email protected]:jsdoc3/jsdoc.git
    git checkout -b upstream/jsdoc jsdoc-upstream/master

    # split off subdir of tracking branch into separate branch

    git subtree split --squash --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc

    # add separate branch as subdirectory on master.
    git checkout master
    git subtree add --prefix=jsdoc-template --squash merging/jsdoc

    # switch back to tracking branch, fetch & rebase.
    git checkout upstream/jsdoc
    git pull jsdoc-upstream/master

    # update the separate branch with changes from upstream
    git subtree split --prefix=templates/default --annotate="[jsdoc] " --rejoin -b merging/jsdoc`
    # switch back to master and use subtree merge to update the subdirectory
    git checkout master
    git subtree merge --prefix=templates/default --squash merging/jsdoc
    ```

    May I never have to google this again.