Skip to content

Push to GitHub

Connect your GitHub once, and every machine you create can clone, push and use gh as you. No SSH key and no token is stored on the machine.

In Machinery, open GitHub and choose Connect GitHub. GitHub asks you to install Deployport’s app and to choose the repositories it can reach, then sends you back to the console.

If the app is already installed on your GitHub account or organization, choose Authorize only instead.

When you launch a machine without a connection, the launch dialog offers Connect GitHub too.

Only an owner of a GitHub organization can connect that organization to your account.

Operators can connect. A developer can connect when their operator adds machinery:ConnectGitHub to the policy that lets them create machines.

Seeing everyone’s connections and removing them is for operators, through machinery:ListGitHubConnections, machinery:RemoveGitHubInstallation and machinery:RemoveGitHubAuthorization.

A machine pushes as the person who created it. Everyone who works on that machine, its assistant included, pushes as that person.

The machine reaches:

  • your own repositories, when Deployport’s app is installed on your GitHub account,
  • an organization’s repositories, when the app is installed on the organization, the repository is in the installation’s selection, and you can write to the repository.

GitHub’s own rules still apply, so branch protection and your organization’s policies decide what a push may change.

No GitHub credential is stored on the machine. When git needs one, it asks the Machinery agent, and Machinery answers with a short-lived token for that request. Nothing is written to disk. A token for an organization’s repository lasts up to an hour. Your own GitHub user token lasts up to 8 hours, and Machinery renews it for you.

The agent writes /etc/machinery/gitconfig and includes it from /etc/gitconfig. It sets three things:

  • git’s credential helper for https://github.com,
  • a rewrite of git@github.com: remotes to HTTPS, so a remote copied from GitHub’s SSH tab works without a key,
  • your commit name and your GitHub noreply address.

Your own settings win. A user.name or user.email in ~/.gitconfig replaces ours, and an empty credential.helper= in your own config turns the helper off. A remote written as ssh://git@github.com/owner/repo is left alone, so it keeps using ssh.

gh signs in as you with no gh auth login. It is not installed on the machine, so install it once:

Terminal window
sudo apt-get update && sudo apt-get install -y gh

When Mecha, the machine’s assistant, makes a commit with git commit, it adds this line to the commit message:

Co-authored-by: Mecha <mecha@deployport.com>

The line is on by default, so anyone reading the history can tell which commits Mecha wrote.

Mecha is not the commit’s author. git records the name and email the machine is set up with, which are those of the person who created the machine once they have connected GitHub. The work shows up under that person’s name, with Mecha beside it.

Commits you make yourself, in your own shell or editor, get no line. A merge that Mecha makes with git merge or git pull gets none either.

For the whole machine:

Terminal window
sudo git config --system mecha.trailer false

For one repository, run inside it:

Terminal window
git config mecha.trailer false

git’s usual spellings work: false, no, off and 0. Set it to true to turn the line back on. A repository’s setting wins over the machine’s, so one repository can keep the line while the rest of the machine turns it off, and removing a repository’s setting falls back to the machine’s.

Mecha reads the setting each time it makes a commit, in the repository the commit goes into, so a change applies to its next commit. Commits it has already made keep their line.

Verify. The next commit Mecha makes carries no trailer. In that repository, git log -1 --format=%B prints the message without the Co-authored-by: Mecha line.

Mecha runs as the machine’s login user, so a git config --global setting made by that user counts too.

  • Terminate the machine. It is refused new tokens at once. A token it already has works until it expires.
  • Disconnect a person. On the GitHub page, an operator chooses Disconnect on the person’s row, or runs deployport machinery github disconnect <github-user-id>. Every new token is refused, and each machine removes its git setup at its next check-in, within five minutes.
  • Remove an installation. Choose Remove on the installation, or run deployport machinery github remove <installation-id>. New tokens for its repositories are refused. Deployport’s app stays installed on GitHub until you uninstall it there.
  • Lose write access on GitHub. New tokens for that repository stop within a minute.

A connection that GitHub stops renewing shows Expired on the GitHub page. Choose Reconnect on your own row to connect again.

Each refusal says what to do next, and git prints it before its own line, fatal: credential helper '/usr/local/bin/machinery-agent github credential' told us to quit. The messages you can see are:

  • The person who created this machine has not connected GitHub. They can connect it from the console's GitHub page.
  • Deployport's GitHub app does not reach {owner}/{repo}. Install it on {owner} from the console's GitHub page, or add the repository to the installation on GitHub.
  • {owner} is another person's GitHub account. This machine pushes as {login}.
  • Deployport's GitHub app is installed on {owner} without {owner}/{repo}. Add the repository to the installation on GitHub.
  • {login} cannot write to {owner}/{repo} on GitHub. Ask an admin of {owner} for write access to the repository.
  • The GitHub connection of the person who created this machine has expired. They can reconnect it from the console's GitHub page.
  • GitHub did not answer. Try again in a moment.

The ones that name the console’s GitHub page print its address on the next line.

  • The first push to a repository that GitHub created a moment ago can answer remote: Internal Server Error. Wait a minute and push again.
  • A long gh command can fail once if its token is renewed while it runs. Run it again.
Terminal window
deployport machinery github list

Your GitHub account is in the installations table and your own connection is in the authorizations table under your login. The console’s GitHub page shows the same two lists.