Deleting A File From The GitHub Server

Goal: In this exercise you will familiarize yourself with the process of removing a file from your repo on the GitHub server.

WARNING: You must do this exericse BEFORE doing the exercise about working with a git repo locally.
In this exercise you make a change to your copy of a project online.  In the next exercises you will download your copy and continue to modify it.

You must do this exercise first so that the changes you make at the end of this exercise will be downloaded in the next exercise.
 Your project on the GitLab server
Roadmap for these tutorials

Deleting (Removing) A File From GitHub

Occassionally you may want to remove (delete) a file from your repo on GitHub.com itself.  Let's see how to do that in this tutorial. 

WARNING: Deleted files remain in your project's history

Once you've added a file to your git repo it's very hard to remove it.  This is especially true if the file has been there for several changes (for several commits). 

After you delete a file it will appear to be removed, but the file will still exist in the project's history.  You (or someone else) can still find it by clicking on the Commits link in the left-hand column of GitHub and going backwards until they find a commit that still had the file in it, and then asking git to show them the project at that point in time.

This behavior is exactly what you want - if you accidentally delete a file you can still go 'back in time' and find it.

The first step is to log into GitHub and find the repo that you wish to work with.  Since this was covered in a prior tutorial we're not going to cover it again here.

Once you've open the repository you should find the file that you want to delete and click on it's name.  Let's say that we accidentally added the file named "logo_bluegrey_4in_jpg.jpg" and we now want to get rid of it.  We can open the file by clicking on it's name next to the '1' in the below image:

Deleting a file: open it!

Once you've opened up the file on GitHub you can delete (remove) it, using the delete icon (which looks like a trash can, and is pointed to in the below image):

Deleting: Trash icon

Like any other change you want to make to your repo on GitHub, you'll need to provide a commit message before pressing the 'Delete' button.

It's a good idea to briefly explain why you're deleting the file, just in case a coworker comes along and wonders why the file is gone:

Deleting a file: Commit!

Once you've added a message you can click the 'Commit Changes' button to tell GitHub to remove the file.

As always, you should double check your work. 

In this case we'll look at the page that GitHub shows us after we committed our changes:

Deleting a file: confirmed!

Immediately after deleting the file we should see a mesage at the top of the page (next to the '1', above) confirming that the file was deleted (removed). 

Further, we can change the list of files (next to the '2', above) at any time in order to verify that the file is no longer listed.