W
W
wyfinger2015-06-26 04:59:32
git
wyfinger, 2015-06-26 04:59:32

Copy file from one branch to another on git push?

Good afternoon.
Background: I decided to read one smart book and master LaTeX in one, I'm slowly typesetting. I am versioning in git on github , on github pages I made a one-page site to display the book (PDF.JS).
Problem: the markup of the book is stored in one branch (master), and the page of the site in another (gh-pages), I wanted to display the latest version of the pdf file from the master branch ( https://github.com/wyfinger/Ulianov1970/raw/master. .. ), but XMLHttpRequest cannot request a file from another domain.
Question: Is it possible to make a pre-push hook, in which a file from the master branch would be copied to the gh-pages branch, so as not to do it every time on my own?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wyfinger, 2015-06-27
@wyfinger

For some reason, the push hook does not work in my version of git (1.8.1 win), although it seemed to work at work.
Therefore, I made a hook on the commit:

#!/bin/sh

if [ "$(git branch | grep '* master')" = '* master' ]; then

if [ -f ././main.pdf ]; then
  echo "File 'main.pdf' exists, trying to copy it to gh-pages branch"
else
 exit 0
fi

  cp ./main.pdf /delete_me.pdf
  git checkout gh-pages
  cp /delete_me.pdf ./main.pdf
  git add ./main.pdf
  rm -i /delete_me.pdf < y
  git commit -a -mCopy
  git checkout master
  
else
  exit 0
fi  

exit 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question