I’ve tried following the instructions for GitHub deployment using the gh-pages
branch version as documented at http://gohugo.io/tutorials/github-pages-blog/. Up to the git worktree
line, everything appears to work fine and make sense. Here’s what I’m getting after this:
$ git worktree add -B gh-pages public origin/gh-pages
Branch gh-pages set up to track remote branch gh-pages from origin.
Preparing public (identifier public)
fatal: Refusing to point HEAD outside of refs/
Also,
$ git --version
git version 2.7.4
While I realize this is more of a git
usage issue than a hugo
one, I’m hoping someone watching who uses the worktree
feature for their deployment can help with this. Fwiw, the clone
method mentioned for older git
versions works fine for me.
Thanks!
Did you ever find the solution for this particular problem?
I ended up not using worktrees. I started out by following the Git 2.4 and earlier instructions but have since modified them. In case it’s helpful, here’s the script that I’m using:
#!/bin/sh
set -e
DIR=$(dirname "$0")
cd $DIR/..
if [ "$(git status -s)" ]; then
echo "The working directory is dirty. Please commit any pending changes."
exit 1;
fi
SHA=$(git rev-parse HEAD)
if [ -n "$GITHUB_API_TOKEN" ]; then
GIT_USER_ARGS="-c user.name='travis' -c user.email='travis'"
fi
echo "Deleting old publication"
rm -rf public
mkdir public
echo "Creating gh-pages branch in ./public"
git -C public init
git -C public checkout -b gh-pages
echo "Generating site"
hugo
echo "Updating gh-pages branch"
git -C public add --all
git -C public $GIT_USER_ARGS commit -m "Publishing to gh-pages ($SHA)"
echo "Pushing gh-pages branch"
if [ -n "$GITHUB_API_TOKEN" ]; then
# CI deployment
git -C public push -f https://fhunleth:$GITHUB_API_TOKEN@github.com/fhunleth/embedded-elixir gh-pages:gh-pages 2>&1 | \
sed s/$GITHUB_API_TOKEN/HIDDEN/g
else
# Manual deployment
git -C public push -f git@github.com:fhunleth/embedded-elixir.git gh-pages
fi
This is fixed in git now, I’m running 2.13.1 and works as expected.
2 Likes
I also met this problem with git version 2.7.4
. Upgrade to 2.14.2 solved the problem, besides you can read this post for simpler solution
1 Like