How to Use Git and GitHub for a Website: A Practical Workflow for Beginners
GitGitHubweb developmentdeploymentversion controldeveloper tools

How to Use Git and GitHub for a Website: A Practical Workflow for Beginners

HHelps Website Editorial Team
2026-11-05
6 min read

Learn a practical Git and GitHub workflow for building, reviewing, troubleshooting, and deploying a website safely.

Git and GitHub give a website a reliable history, a safer way to test changes, and a repeatable path from local files to a published site. This beginner-friendly tutorial explains how to create a repository, commit work, use branches, review edits, resolve common conflicts, and connect the finished project to a deployment service.

Overview

Git is the version-control system that records changes to files on your computer. GitHub is a web platform that stores Git repositories and adds collaboration, review, issue tracking, and integrations. You can use Git without GitHub, but the two are commonly used together for website development.

A simple workflow looks like this:

  1. Create or download the website files.
  2. Initialize a Git repository and make an initial commit.
  3. Push the repository to GitHub.
  4. Create a separate branch for each meaningful change.
  5. Review and merge completed work into the main branch.
  6. Deploy the main branch through a hosting or deployment service.
  7. Repeat the cycle while keeping the live site and repository organized.

This process works well for a static HTML, CSS, and JavaScript site. Framework-based projects may add build commands, environment variables, and deployment settings, but the version-control principles remain similar. If you are still planning the site itself, see this step-by-step guide to building a website from scratch.

Step-by-step workflow

1. Install Git and configure your identity

Install Git for your operating system, then open a terminal and set the name and email that should appear on your commits:

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

Use an email address associated with your GitHub account if you want your commits to connect to that profile. You can check the saved settings with git config --global --list.

2. Prepare the website directory

Place the project files in one folder. A small static website might contain index.html, a css directory, a js directory, and an images directory. Before tracking the files, create a .gitignore file for content that should not be committed.

Typical examples include local environment files, dependency directories, generated build output, and operating-system files. The exact entries depend on the tools used by the project. Never commit passwords, API keys, private certificates, or other secrets.

3. Initialize the repository and make the first commit

In the website folder, run:

cd path/to/your-website
git init
git status
git add .
git commit -m "Create initial website"

git status shows which files are untracked or changed. git add places selected changes in the staging area, and git commit records the staged snapshot. Write commit messages that describe the change, such as Fix mobile navigation spacing rather than Update.

4. Create a GitHub repository and connect it

Create an empty repository on GitHub. If the local folder already contains a README and an initial commit, avoid creating another README during repository setup unless you are prepared to reconcile the two histories.

Copy the repository URL and connect it as a remote:

git remote add origin https://github.com/USERNAME/REPOSITORY.git
git remote -v
git branch -M main
git push -u origin main

The remote named origin points to GitHub. The first push may require authentication through GitHub's supported sign-in method. After the upstream branch is established, later updates can usually be sent with git push.

5. Create a branch for each change

Keep the main branch in a usable state and do new work on a separate branch:

git switch main
git pull origin main
git switch -c update-contact-page

Make the change locally, then inspect and commit it:

git status
git diff
git add contact.html
git commit -m "Update contact page"
git push -u origin update-contact-page

git diff helps you review the exact edits before committing. Use a focused branch for one feature, fix, or maintenance task rather than combining unrelated changes.

6. Review and merge the work

Once the branch is pushed, open a pull request on GitHub. Review the changed files, confirm that the description matches the work, and test the branch version locally. If another person reviews the project, use the pull request to discuss specific lines and record any requested adjustments.

After the checks are complete, merge the pull request using the repository's chosen merge method. Then update your local main branch:

git switch main
git pull origin main

Delete an old local branch when it is no longer needed with git branch -d update-contact-page. Keeping finished branches tidy makes the project easier to navigate.

7. Deploy the main branch

For a static website, choose a hosting or deployment service that can connect to the GitHub repository. Select the repository and the branch to publish, commonly main. If the site needs a build step, specify the project’s build command and the directory containing the final files. For a plain HTML site, the build command may be unnecessary, while the publish directory must contain the page that should load first.

After deployment, open the provided address and test the site as a visitor. If you connect a custom domain, check the host’s required DNS records and allow for DNS changes to become visible. This DNS settings guide covers the records and common connection problems that can affect a domain.

Tools and handoffs

A dependable workflow separates responsibilities:

  • Code editor: edit HTML, CSS, JavaScript, configuration files, and documentation.
  • Terminal: run Git commands, local development servers, tests, and build tasks.
  • Git: create commits, compare versions, switch branches, and recover earlier work.
  • GitHub: store the remote repository, review pull requests, and document issues.
  • Deployment service: build and publish the selected branch.
  • Domain and DNS provider: direct the custom domain to the published site.

Keep a short project README with the purpose of the site, local setup instructions, the required runtime or tools, the development command, the build command, and the deployment branch. This handoff document reduces guesswork when the project changes owners or returns after a long pause.

Quality checks

Before merging or publishing, use a small repeatable checklist:

  • Run git status and confirm there are no unintended files.
  • Review git diff for accidental edits, debug code, or secrets.
  • Open the changed pages on a narrow and wide screen.
  • Test navigation, forms, images, downloads, and external links.
  • Check the browser console for JavaScript errors.
  • Confirm that relative paths work from the deployed URL, not only from a local file.
  • Verify that the deployment service completed successfully.
  • Test the custom domain, HTTPS connection, and important redirects if a domain is configured.

If deployment fails, first compare the deployment log with the local build command. Then check the selected branch, publish directory, required environment variables, and filename capitalization. For broader DNS, SSL, hosting, and site errors, use this website troubleshooting checklist.

To resolve a basic merge conflict, run git pull only when your local work is committed or safely stored, open each conflicted file, remove the conflict markers, choose the intended content, and then run:

git add path/to/resolved-file
git commit -m "Resolve merge conflict"
git push

Do not resolve a conflict by blindly keeping one entire version. Compare the surrounding code and test the result afterward.

When to revisit

Revisit this workflow whenever your Git client, hosting provider, framework, authentication method, or deployment settings change. Platform interfaces and recommended connection methods can move, so confirm current instructions in the relevant tool’s documentation before changing a production repository.

Also review the process when the project gains collaborators, changes from a static site to a framework, introduces automated tests, adds private configuration, or moves to a new domain. These changes may require branch protection, environment variables, preview deployments, a revised .gitignore, or updated README instructions.

For a practical maintenance routine, schedule a periodic check of repository access, deployment status, domain settings, backups, and the list of active branches. Start each update by pulling the latest main branch, create a focused branch, commit small understandable changes, test before merging, and verify the live site after deployment. That simple sequence turns GitHub from a file storage location into a reusable website version-control workflow.

Related Topics

#Git#GitHub#web development#deployment#version control#developer tools
H

Helps Website Editorial Team

Technical Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.