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 need | Version / notes |
|---|---|
| Git | Installed and configured – see the Git guide |
| GitHub account | With two-factor authentication enabled |
| gh CLI (optional) | GitHub’s command-line tool |
3. Local setup
1Secure your account
Enable two-factor authentication (Settings → Password and authentication). Use an authenticator app or passkey.
2Add your SSH key
Copy your public key and add it under Settings → SSH and GPG keys → New SSH key, then test.
BASHcat ~/.ssh/id_ed25519.pub ssh -T git@github.com # Hi you! You've successfully authenticated...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
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.
BASHcd my-project git init && git add . && git commit -m "Initial commit" gh repo create my-project --private --source=. --push2Open a pull request
Push a branch and open a PR for review.
BASHgit 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 --web3Review and merge
Reviewers comment on lines and approve; merge with Squash and merge for a tidy history, then delete the branch.
BASHgh pr merge --squash --delete-branch4Protect 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.
# Repository secrets (examples)
SSH_PRIVATE_KEY # deploy key for your server
PROD_HOST # e.g. 203.0.113.10
DATABASE_URL # used by deployment jobsKey dependencies
| Package / tool | Used for |
|---|---|
Pull requests | Code review and discussion |
GitHub Actions | CI/CD workflows |
Dependabot | Automatic dependency update PRs and security alerts |
GitHub Pages | Free static hosting |
GHCR (Packages) | Container registry ghcr.io |
gh CLI | Command-line access to all of the above |
Folder structure
my-project/
├── .github/
│ ├── workflows/ # GitHub Actions
│ ├── dependabot.yml
│ ├── CODEOWNERS # automatic reviewers
│ └── pull_request_template.md
├── README.md
└── LICENSEEssential commands
| Command | What it does |
|---|---|
gh repo create | Create a repository |
gh repo clone owner/repo | Clone |
gh pr create / list / checkout / merge | Work with pull requests |
gh issue create | Open an issue |
gh run watch | Follow an Actions run |
gh secret set NAME | Add 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
| Requirement | Recommendation |
|---|---|
| Static site | Build output (HTML/CSS/JS) – GitHub Pages |
| Dynamic app | A server or cloud target + an Actions workflow |
| Custom domain | DNS records at your registrar |
| Secrets | Deploy keys and tokens stored as encrypted secrets |
Deployment steps
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.ymlname: 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@v42Use a custom domain
In Settings → Pages → Custom domain enter
www.example.com. At your DNS provider add a CNAMEwww→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.io3Turn on Dependabot
Weekly update PRs for npm packages and Actions.
.github/dependabot.ymlversion: 2 updates: - package-ecosystem: npm directory: "/" schedule: { interval: weekly } - package-ecosystem: github-actions directory: "/" schedule: { interval: weekly }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.
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
mainwith 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.