Github - Removing Files from Git

The problem

Sometimes a file is gone locally.. but still exists on GitHub or GitHub Pages.
This usually happens after renaming or deleting files.

In this section you will learn:
how to check what Git is actually tracking, and how to remove a file so it disappears online as well.


Workflow Explained (problem)

  1. You create and push a file to GitHub.
  2. You rename or delete the file locally.
  3. You push again.
  4. The old file still exists online.

This is confusing.. but very common.


Why this happens

  • Git tracks files, not folders
  • Deleting or renaming locally does not always update Git automatically
  • GitHub only shows what exists in the published branch

Step by Step – Guide

Prerequisites
  • Git installed locally
  • A GitHub repository
  • Basic Terminal knowledge

Step 1

Create and publish a file

mkdir git-remove-file-demo
cd git-remove-file-demo
git init
echo "First version" > page.html
git add .
git commit -m "Add initial file"

Push the project to GitHub.





Important rule

If a file exists online, it exists in the branch GitHub publishes.

Deleting a file locally is not enough.


Common mistake

Renaming files like this:

mv old.html new.html

Instead, use:

git mv old.html new.html

This allows Git to understand the change correctly.


Now what?

Success

Well done!
You now know how to remove files from GitHub properly — even when they refuse to disappear.


Git – Documentation

Documentation

Finished

Back to Overview: Developer Fundamentals