This is a script for deploying generated files to a git branch, such as when building a single-page app using Yeoman and deploying to GitHub Pages. Unlike the git-subtree approach, it does not require the generated files be committed to the source branch. It keeps a linear history on the deploy branch and does not make superfluous commits or deploys when the generated files do not change.
Download the script (
wget https://github.com/X1011/git-directory-deploy/raw/master/deploy.sh && chmod +x deploy.sh) and edit these variables within it as needed to fit your project:
- deploy_directory: root of the tree of files to deploy
- deploy_branch: branch to commit files to and push to origin
- default_username, default_email: identity to use for git commits if none is set already. Useful for CI servers.
- repo: repository to deploy to. Must be readable and writable. The default of "origin" will not work on Travis CI, since it uses the read-only git protocol. In that case, it is recommended to store a GitHub token in a secure environment variable and use it in an HTTPS URL like this:
repo=https://$GITHUB_TOKEN@github.com/user/repo.gitWarning: there is currently an issue where the repo URL may be output if an operation fails.
You can also define any of variables using environment variables and configuration files:
The script will set these variables in this order of preference:
- Defaults set in the script itself.
- Environment variables.
.envfile in the path where you're running the script.
- File specified on the command-line (see the
Whatever values set later in this list will override those set earlier.
Do this every time you want to deploy, or have your CI server do it.
- check out the branch or commit of the source you want to use. The script will use this commit to generate a message when it makes its own commit on the deploy branch.
- generate the files in
- make sure you have no uncommitted changes in git's index. The script will abort if you do. (It's ok to have uncommitted files in the work tree; the script does not touch the work tree.)
deploy_directoryis a relative path (the default is), make sure you are in the directory you want to resolve against. (For the default, this means you should be in the project's root.)
--help: show the program's help info.
--config-file: specify a file that overrides the script's default configuration, or those values set in
.env. The syntax for this file should be normal
var=value declarations. This option must come first on the command-line.
--message <message>: specify message to be used for the commit on
deploy_branch. By default, the message is the title of the source commit, prepended with 'publish: '.
--no-hash: don't append the hash of the source commit to the commit message on
deploy_branch. By default, the hash will be appended in a new paragraph, regardless of whether a message was specified with
--verbose: echo expanded commands as they are executed, using the xtrace option. This can be useful for debugging, as the output will include the values of variables that are being used, such as $commit_title and $deploy_directory. However, the script makes special effort to not output the value of $repo, as it may contain a secret authentication token.
--allow-empty: allow deployment of an empty directory. By default, the script will abort if
deploy_directory is empty.