How to automate merge in git / github with hook or another tool?

4

I have a repository in Github and I have created a page in Github for this repository. With this, whenever I make changes in the master branch, I need to enter the gh-pages branch, make a git merge master and send to the appropriate branch.

Can you automate this task, whenever I make a git push origin master already send all changes to the gh-pages branch?

Come on, basically the steps I do are:

git add . // para adicionar todos arquivos
git commit -m "traduzido tais arquivos"
git push origin master // sei que é bom fazer um pull antes

And when I do this push, then run that automation there in Github, which should be something like:

git checkout gh-pages
git merge master
git push origin gh-pages
git checkout master

I do not know if you can improve these 4 steps above, but that's what I would not like to do every time I push.

    
asked by anonymous 28.07.2016 / 00:58

2 answers

1

Mirroring master code using Git Hooks

If you want to put in hook of push , rename the file pre-push.sample to pre-push and paste the following code:

echo $DEPLOYING
if [ -z "$DEPLOYING" ]; then
  echo 'Deploying site...'
  export DEPLOYING='yes'
  git checkout gh-pages
  git merge master
  git push origin gh-pages
  git checkout master
  unset -v DEPLOYING
  echo 'done!'
fi
exit 0
    
28.07.2016 / 19:07
0

With Jekyll

If you were using Jekyll you could create a script with the following command:

#!/bin/bash
git push origin 'git subtree split --prefix _site master 2> /dev/null':gh-pages --force

Then just run the script, in my case

./deploy

You can still make it even more dynamic by using the script :

if [ -z "$DEPLOYING" ]; then
  echo 'Deploying site...'
  export DEPLOYING='yes'
  git push origin 'git subtree split --prefix _site master 2> /dev/null':gh-pages --force
  unset -v DEPLOYING
  echo 'done!'
fi
exit 0

By simply passing the directory as a parameter:

deploy path/to/your/site

Or tell me when prompted by the script.

Jekyll with Hook

If you want to put in hook of push , rename the file pre-push.sample to pre-push and paste the following code:

#!/bin/sh
if [ -z "$DEPLOYING" ]; then
  echo 'Deploying site...'
  export DEPLOYING='yes'
  git push origin 'git subtree split --prefix _site master 2> /dev/null':gh-pages --force
  unset -v DEPLOYING
  echo 'done!'
fi
exit 0
    
28.07.2016 / 20:59