Complete a restart of the question
So, I thought I was explaining this question very simply and directly, but it seems that I am simplifying a lot, so here are some more details. I hope this helps everyone understand that this is not a duplicate either.
I have a repository (project) where I would like to automate the process of pushing commits from one directory to branches to another branch; what I have not met on SO.
Here is my project with its full structure:
[PROJECT MASTER BRANCH] |- gh-pages (directory) |- css (directory) |- index.html (file) |- readme.md (file) [PROJECT gh-pages BRANCH] |- (empty at the moment)
What I hope to do is create a hook that automatically processes the changes in my gh-pages directory from the main branch and copies / clones / replaces them (depending on which term is suitable for use) into the gh-pages branch website projects. Below is an example with all other files:
[PROJECT MASTER BRANCH] |- gh-pages (directory) <=== SEE UPDATE BELOW [A] | |- css (directory) | | |- style.css (file) | |- index.html (file) [PROJECT gh-pages BRANCH] |- css (directory) <=== SEE UPDATE BELOW [B] | |- style.css (file) |- index.html (file)
I am completely new to this level of Git hub. I usually just stick to the basics and never use a terminal / shell. Therefore, to clarify what I hope to do, I would like to:
- You need to work only in [Main Branch]. All the changes that I need to make to the [gh-pages Branch] I do in the gh-pages directory [Master Branch]
- Is it advisable to accomplish this by adding a simple file, which seems to be sending after receiving?
Here is some code that I tried to use after receiving (I did this from learning a few things), but it doesnโt work:
#!/bin/bash while read oldrev newrev refname do branch=$(git rev-parse --symbolic --abbrev-ref $refname) if [ "master" == "$branch" ]; then git checkout gh-pages git checkout master -- gh-pages git add gh-pages git commit -m "Updating project website from 'master' branch." fi done
Note
As mentioned in my comment: this is not a duplicate. This does not ask how to click, but rather how to use other commands that automatically run when I do a normal push. These commands will do the extra work mentioned in my OP.
UPDATE
I added these arrows to parts of my code that I am talking about below: <===
[A] What should happen here is that Git should recursively read the gh-pages main branches directory and copy only what is updated (or all, if it's easier) to the gh-pages branch.
[B] So, if the gh-pages directory in master has an index.html file, and the css folder with the style.css file should copy only this structure, not the gh-pages of the directory itself. The following is an example of a bad hook that also copies the gh-pages directory:
[PROJECT gh-pages BRANCH] |- gh-pages (Directory) <=== NOT SUPPOSED TO HAPPEN | |- css (directory) | | |- style.css (file) | |- index.html (file)
In addition, the hook should not copy any files other than what is inside the gh pages. Even if several other files have been modified in the main branch, gh-page copy files must be copied.
[C] NEW CODE - this works, but causes an error:
#!/bin/bash branch=$(git rev-parse --abbrev-ref HEAD) if [ "master" == "$branch" ]; then git fetch && git checkout gh-pages git checkout master -- gh-pages/* git add -A git commit -m "Updating project website from 'master' branch." git push -u origin gh-pages fi
This does not work for two reasons. 1) If the repo lags behind fixing, he can not cope with it, he will fail; if attraction is used instead of pushing, the local repo is wiped like this:

If I leave the selection, the local repo will remain as it should:

2) The entire directory of gh-pages is copied to the gh-pages branch, and not just the files inside it.