I'm developing a jQuery plugin that's being hosting on GitHub. It has a demo included of which I'm manually copying and pushing to the branch gh-pages
, what I'd like to do is have it so when I push a change to master
it is automatically pushed to gh-pages
, or at least a setup where they are mirrored.
I've already seen this question but not sure if it really answers my question with regard to these requirements:
- I use Tower, I don't mind using the terminal (Mac) to make changes to config, so long as the solution works with this GUI.
- I only want this 'mirroring' on certain repos, not on all of them on my machine.
Cheers
Add the following 2 lines to the
[remote "origin"]
section of.git/config
:Every time you
push
it will automatically push master to gh-pages as well. I'm using this for the jQuery Lifestream project.I'm adding further explanation to @denbuzze and @MCSDWVL answers.
If you want to push both to
master
andgh-pages
automatically each time you rungit push origin
, you probably want to add a Refspec to the git config of your repo.So, according to the git-scm book, you can add two RefSpecs, by adding two
push
values to the repo config file.git/config
:That will cause a
git push origin
to:master
branch to the remotemaster
branchmaster
branch to the remotegh-pages
branchby default.
Note: using a
+
before the spec causes to force push to the repo. Use it with caution:OR you can just use the cmd below, this will push your local master branch to gh-pages master branch.
git push -f origin master:gh-pages
I personally like to wrap this in an alias:
This mirrors your master to
gh-pages
, pushes to github, then switches back the previous branch you were working on.Do not do what denbuzze suggests above!! The + (plus sign) in the push makes it quietly accept non-fastforward updates. I found out the hard way that this can irrevocably cause work to be lost by leading to dangling commits. Simply removing the plus signs makes this a safer approach.
now instead of causing a force update this will cause a warning & pull suggestion
commit and push to master..
then :