Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Ignoring Files after Initial Commit | More Advanced Interaction
Git Essentials
course content

Contenido del Curso

Git Essentials

Git Essentials

1. Introduction to Git
2. More Advanced Interaction
3. Undoing Changes
4. Working with Branches in Git

bookIgnoring Files after Initial Commit

If you've already committed files that you now want to ignore, follow these steps:

  1. Add the files to your .gitignore;
  2. Remove the files from the repository (without deleting them locally) using git rm --cached;
  3. Commit the changes.

Workflow Example

In most cases, configuration files often contain private information, so they shouldn’t be tracked at all. In order to avoid accidentally adding such files to Git, it’s better to ignore them. We’ll do the same with our config.txt file which has already been committed.

Take a look at the following illustration of our workflow:

Let’s first add config.txt to the list of ignored files in .gitignore:

We’ll then run the git rm command with the --cached flag to remove it from our repository without deleting:

Now, let’s check the status of our working tree and staging area:

As you can see, the deletion of our config file is already staged, however, we still have to add the .gitignore file, and then we can commit these changes:

The commit is successful. Now, let’s verify that the config.txt file is indeed ignored. We’ll append a new line with a certain example password to it using the echo command:

Finally, let’s check the status of our working tree:

Our file was modified, but it’s not tracked by Git, so the working tree is clean.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 6
some-alt