Last item I want to talk about is the .gitignore.
So .gitignore is about files in a directory that you don't want to be cloned to the git repository.
Think about files that contain sensitive values like passwords.
Excluding these files from being synchronized is not difficult.
You create a text file with the name .gitignore that lists all files that need to be ignored.
A .gitignore file can be added to the current git project directory.
Use the following to create a global .gitignore file.
gitconfig --global core.excludes file
and that allows you to put .gitignore underscore global in your home directory.
And in this file you list files that should be ignored if they occur in any git repository.
So no absolute file names, just the name of the file, the relative name of the file will do.
Let me show you.
So let's do echo password greater than password.txt
sensitive value. And now I'm going to use echo password.txt
greater than .gitignore.
And I'm just using echo with command output redirection as an editor.
So this creates a .gitignore that lists the name of the file.
Then I'm using git add star.
And oh, what do we see? Following paths are ignored password.txt.
That's exactly what we need, right? And git status is
showing me that there is an untracked file with .gitignore.
And git commit minus m ignore file
edit going to commit it.
And yeah, what do we see? It's not going to commit it because it's a .gitignore
and .gitignore stays here. But in the
top of my git commit I can see that my branch is a head of origin
main by one commit. And that means that I need to git push
to synchronize everything. And now we can see that everything is
all right and the .gitignore is included so I won't get my
password.txt on the remote.