Contenido del Curso
Git Essentials
Git Essentials
Ignoring Files after Initial Commit
If you've already committed files that you now want to ignore, follow these steps:
- Add the files to your
.gitignore
; - Remove the files from the repository (without deleting them locally) using
git rm --cached
; - 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.
¡Gracias por tus comentarios!