Get startedGet started for free

Modifying a repo structure

1. Modifying a repo structure

Hi, my name is George, and in this chapter we'll be examining how to work with repos in GitHub. We'll start by looking at how to modify a repo, including adding, editing, and deleting files and directories.

2. Creating a new file

We've seen how to add a README and dot-gitignore file. Let's see how to add other files. We'll be working in the soccer analysis GitHub repo, a project analyzing soccer data from three top-tier European soccer leagues - Serie A, La Liga, and the Premier League. If we want to create a file, we select the add file button and choose create new file.

3. Naming the file

We enter the name of our file at the top, including a file extension. Here we create requirements-dot-txt, a text file containing the Python packages for our project.

4. Editing the new file

In the next section, we add the file's contents, which are lines to install NumPy, pandas, and Matplotlib.

5. Committing the new file

Next, we scroll down to save the new file. We add a commit message in the first text box, which should be brief but descriptive. Our message is add requirements file.

6. Committing the new file

There is an optional extended description text box. Here, we choose to leave it blank.

7. Committing the new file

Underneath, we have two options for how to save the file. We can commit directly into our current branch or create a new branch for this commit and start a pull request.

8. Committing the new file

We'll commit directly to our current branch, which is a more common approach. After the commit executes, GitHub returns us to our repo's Code section where we can see the requirements-dot-txt file in the list of files.

9. Uploading a file

Alternatively, if we have a file saved locally and need to add it to our repo, we can select add file and this time choose Upload files.

10. Uploading a file

We can then drag any file we choose to upload it; here, we upload a visualization of attendance figures for various teams in La Liga from a local directory into the repo.

11. Uploading a file

We put a commit message, Add la liga attendance plot, and make a commit. Again, GitHub returns us to the repo's Code section.

12. Creating a new directory

What about creating a new directory? Let's make one to store exploratory data analysis results, called EDA. To do this, we again use the create new file link. This time, we write the name of our directory followed by a forward slash. GitHub won't allow us to create an empty directory, so we need to add a file. We'll add a README as a placeholder and can add detail to it later.

13. Creating a new directory

We make a commit with the message Add EDA directory.

14. Modifying a file

If we need to modify an existing file, we click on it, showing its contents. We decide we will also use the seaborn Python package, so we need to add that to our requirements file. Clicking on the pencil icon will open up the file. We can now add or remove any content we like.

15. Modifying a file

We add the version of seaborn required for the project and again make a commit to save the updated file to the repo.

16. Deleting a file

We can also delete a file in GitHub. We decide that we won't need a dot-gitignore file for this project. To remove it, we first click on the file.

17. Deleting a file

To the right of the pencil icon is a bin. We click this icon to delete the file.

18. Deleting a file

To save the repo with the file removed, we then make a commit.

19. Let's practice!

Now let's check your understanding of how to modify repo contents in GitHub!