DevOps & Deployment

GitHub Setup & Deployment Guide

Host your Git repositories, review code with pull requests, protect branches, store secrets and deploy – including free GitHub Pages hosting.

Updated Official documentation ↗

1. Introduction & use cases

GitHub hosts Git repositories and adds collaboration tools on top: pull requests for code review, issues and projects for planning, Actions for CI/CD, Packages for container images, Pages for free static hosting, and security features such as Dependabot and secret scanning.

It is free for public and private repositories, with paid plans for larger teams and organisations.

Where it is used

  • Storing code and sharing it with a team or the public
  • Code review with pull requests
  • Automating tests and deployments with GitHub Actions
  • Hosting documentation and static sites on GitHub Pages

2. Prerequisites

You needVersion / notes
GitInstalled and configured – see the Git guide
GitHub accountWith two-factor authentication enabled
gh CLI (optional)GitHub’s command-line tool

3. Local setup

  1. 1Secure your account

    Enable two-factor authentication (Settings → Password and authentication). Use an authenticator app or passkey.

  2. 2Add your SSH key

    Copy your public key and add it under Settings → SSH and GPG keys → New SSH key, then test.

    BASH
    cat ~/.ssh/id_ed25519.pub
    ssh -T git@github.com
    # Hi you! You've successfully authenticated...
  3. 3Install and log in to the GitHub CLI (optional)

    gh makes repository and PR tasks scriptable.

    BASH
    # macOS: brew install gh   ·   Windows: winget install GitHub.cli   ·   Linux: see cli.github.com
    gh auth login
    gh auth status

4. Create & run a project

  1. 1Create a repository and push

    Either click New repository on github.com and follow the commands it shows, or use gh from your project folder.

    BASH
    cd my-project
    git init && git add . && git commit -m "Initial commit"
    gh repo create my-project --private --source=. --push
  2. 2Open a pull request

    Push a branch and open a PR for review.

    BASH
    git switch -c feature/about-page
    # ...edit...
    git commit -am "Add about page"
    git push -u origin feature/about-page
    gh pr create --fill
    gh pr view --web
  3. 3Review and merge

    Reviewers comment on lines and approve; merge with Squash and merge for a tidy history, then delete the branch.

    BASH
    gh pr merge --squash --delete-branch
  4. 4Protect the main branch

    Settings → Rules → Rulesets (or Branches): require pull requests, at least one approval and passing status checks before merging into main; block force pushes.

✅ When it works you should see output like Figure 1.

5. Development configuration

Environment variables

Store secrets in Settings → Secrets and variables → Actions (or per environment). They are encrypted and only available to workflows – never commit them.

Settings → Secrets and variables
# Repository secrets (examples)
SSH_PRIVATE_KEY      # deploy key for your server
PROD_HOST            # e.g. 203.0.113.10
DATABASE_URL         # used by deployment jobs

Key dependencies

Package / toolUsed for
Pull requestsCode review and discussion
GitHub ActionsCI/CD workflows
DependabotAutomatic dependency update PRs and security alerts
GitHub PagesFree static hosting
GHCR (Packages)Container registry ghcr.io
gh CLICommand-line access to all of the above

Folder structure

project structure
my-project/
├── .github/
│   ├── workflows/        # GitHub Actions
│   ├── dependabot.yml
│   ├── CODEOWNERS        # automatic reviewers
│   └── pull_request_template.md
├── README.md
└── LICENSE

Essential commands

CommandWhat it does
gh repo createCreate a repository
gh repo clone owner/repoClone
gh pr create / list / checkout / mergeWork with pull requests
gh issue createOpen an issue
gh run watchFollow an Actions run
gh secret set NAMEAdd an Actions secret

6. Production deployment

GitHub can deploy for you in two common ways: GitHub Pages for static sites (free HTTPS, custom domains), and GitHub Actions for building and deploying anything else to your servers or cloud.

Server & hosting requirements

RequirementRecommendation
Static siteBuild output (HTML/CSS/JS) – GitHub Pages
Dynamic appA server or cloud target + an Actions workflow
Custom domainDNS records at your registrar
SecretsDeploy keys and tokens stored as encrypted secrets

Deployment steps

  1. 1Enable GitHub Pages with Actions

    Settings → Pages → Build and deployment → Source: GitHub Actions. Add this workflow (example for a Vite/React build in dist/).

    .github/workflows/pages.yml
    name: pages
    on:
      push:
        branches: [main]
    permissions:
      contents: read
      pages: write
      id-token: write
    jobs:
      deploy:
        runs-on: ubuntu-latest
        environment:
          name: github-pages
          url: ${{ steps.deployment.outputs.page_url }}
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-node@v4
            with: { node-version: lts/*, cache: npm }
          - run: npm ci && npm run build
          - uses: actions/upload-pages-artifact@v3
            with: { path: dist }
          - id: deployment
            uses: actions/deploy-pages@v4
  2. 2Use a custom domain

    In Settings → Pages → Custom domain enter www.example.com. At your DNS provider add a CNAME www → you.github.io (for the apex domain use the A records GitHub documents). Tick Enforce HTTPS once the certificate is ready.

    OUTPUT
    # DNS
    # CNAME  www   you.github.io
  3. 3Turn on Dependabot

    Weekly update PRs for npm packages and Actions.

    .github/dependabot.yml
    version: 2
    updates:
      - package-ecosystem: npm
        directory: "/"
        schedule: { interval: weekly }
      - package-ecosystem: github-actions
        directory: "/"
        schedule: { interval: weekly }
  4. 4Deploy to your own server

    For servers, add the SSH key and host as secrets and use a workflow – see the GitHub Actions guide.

🗺 The whole path from your code to the live site is drawn in the deployment diagram.

7. Images & screenshots

Illustrations drawn for this guide from the commands above. Product dashboards change often, so for screens such as cloud consoles follow the step text and the official documentation.

terminal$ gh repo create my-project --private --source=. --push✓ Created repository you/my-project on GitHub https://github.com/you/my-project✓ Added remote git@github.com:you/my-project.git✓ Pushed commits to git@github.com:you/my-project.git$ gh pr create --fillhttps://github.com/you/my-project/pull/1
Figure 1: terminal output of the sample GitHub project (section 4).
1Push branch2Pull request +review3Merge to main4Actions build5Pages / serverlive
Figure 2: production deployment flow (section 6).
my-project/├── .github/│ ├── workflows/ # GitHub Actions│ ├── dependabot.yml│ ├── CODEOWNERS # automatic reviewers│ └── pull_request_template.md├── README.md└── LICENSE
Figure 3: project folder structure (section 5).

8. Common errors & solutions

remote: Support for password authentication was removed

Use an SSH key or a personal access token (HTTPS), or log in with gh auth login.

Permission to owner/repo.git denied

Your account lacks write access, or a different SSH key/account is being used. Check with ssh -T git@github.com.

GitHub Pages shows 404

The workflow has not deployed yet, the artifact path is wrong, or a SPA needs base set to /repo-name/ when not using a custom domain.

Cannot merge: required status check is expected

Branch protection waits for a check that never runs on this PR. Fix the workflow trigger or the check name in the ruleset.

File over 100 MB rejected

GitHub blocks large files. Remove it from history or use Git LFS / object storage.

Best practices

  • 2FA for every account; least-privilege team permissions.
  • Protect main with required reviews and checks.
  • Use CODEOWNERS for automatic reviewers.
  • Enable Dependabot alerts and secret scanning.
  • Keep a clear README and a LICENSE for public repos.