1

I want to create a github page

My sites are in the master branch. My actual development is in the development branch.

So my workflow simplified is:

git checkout develop
# edit & commit
gulp build-prod
# push

gulp creates a dist folder which contains all files which shall be in the master branch.

So my question is: Is it possible to treat a subfolder of my repo as a branch?
If this is not possible - what would be a good way to work around this problem?

boop
  • 7,413
  • 13
  • 50
  • 94

1 Answers1

2

Is it possible to treat a subfolder of my repo as a branch?

Of course, it is a well known "hack" I described a few years back in "What's the easiest way to deploy a folder to a branch in git?".

When you are in the develop branch, you can add your master branch as a submodule, in a root folder called 'dist':

git checkout develop
git submodule add -b master /url/of/your/repo.git dist
git add .
git commit -m "add dist root submodule folder as same repo, but master branch"
git push

Then:

git checkout develop
# edit & commit
gulp build-prod
cd dist
git add -A .
git commit -m "new build in master"
cd ..
git add .
git commit -m "record new master state"

Don't forget the last 2 commands (add and commit), as they record the gitlink (special entry in the index of the repo) for the dist submodule.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Well this seems correct but it's not working for me right now. A bit long for a comment - tl;dr: the master branch isn't recognized as submodule and `git add [whatever]` in the dist folder just crashs git. I'll investigate it. – boop Aug 19 '15 at 11:13
  • @Bret What OS and version of Git are you using? – VonC Aug 19 '15 at 11:14
  • @VonC Windows 10 // git version 1.9.5.msysgit.0 – boop Aug 19 '15 at 11:15
  • @Brettetete Can you try with a recent version of Git? Git 2.5 is out since yesterday: https://github.com/git-for-windows/git/releases/tag/v2.5.0.windows.1 (http://article.gmane.org/gmane.comp.version-control.msysgit/21805) – VonC Aug 19 '15 at 11:21
  • @Brettetete keep in mind I assume the structure of the `master` branch content would match the one produced by `gulp build-prod` in dist folder. – VonC Aug 19 '15 at 11:32
  • @VonC I did. I created a complete new repository and did what you wrote. This is not working and will crash git everytime. – boop Aug 19 '15 at 11:48
  • @Brettetete strange, I did use it without issue before. – VonC Aug 19 '15 at 11:49
  • @Brettetete what url did you use for the repo when using the `git submodule add` command? – VonC Aug 19 '15 at 12:45