How to automate merge into git / github with hook or other tool?

Asked

Viewed 440 times

4

I have a repository on Github and I created a Github page for that repository. So, every time I make changes to the branch master, I need to get into the branch gh-pages, make a git merge master and send to the appropriate branch.

There are ways to automate this task, for every time I make one git push origin master already send all changes to the branch gh-pages?

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 push that to run this automation there on Github, which should be something like:

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

I don’t know if there’s any way to improve these 4 steps above, but that’s what I wouldn’t want to do every time I push.

  • Quick doubt - why you want to do this?

  • So I don’t have to make a change whenever I have to do the whole process, one day I can forget and break pq’s head a change isn’t appearing.

2 answers

1


Mirroring master code using Git Hooks

In case you want to hook of push, rename the file pre-push.sample for 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
  • Hi Luiz, then, I even understood what happened, but this has to put straight on a hook to be executed, can I do just a push? Thanks

  • @Marcelodiniz for sure!

  • opa, good, and this is what I need. I could tell me which hook would be and how would this file, because I saw that there are several right?!

  • 1

    in the pre-push, I’ll test here to give you the exact answer.

  • @Marcelodiniz see if this solution serves.

Show 1 more comment

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 if you want, using the following 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

Simply pass the directory as parameter:

deploy path/to/your/site

Or inform when prompted by the script.

Jekyll with Hook

In case you want to hook of push, rename the file pre-push.sample for 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.