What Is Git And How Does Git Track Our Project Files?

Image for post
Image for post

What is Git?

Let’s cover the essential techniques we need to add files to a Git repository, to track changes to those files over time, and to view and compare previous versions of the files. Git has helped a lot of developers to handle complex projects. Whether our goal is to manage our own code, to collaborate with other developers, or to contribute to open source projects, Git is a powerful tool that can help us.

Some of Git configurations

  • The first and broadest is the system-level configuration. These are configurations that will apply to every user of your computer by default. Each user could then override it with their own custom configurations, but these are the default if they don’t.
  • These also are configurations that will apply only to a single user, which is going to be most of us most of the time, working as a single user on a machine. On Unix, that’s going to be in our home directory, inside a file called .gitconfig.
  • The third place that we can store configurations is on a project by project basis. In a single project, we can have some configurations that only apply the scope of that project. Most of the time, we probably want our configurations in all of our projects so that we’re familiar with them, and it all kind of looks the same as we move from project to project. But there may be special cases where we want something different in a project. So what are the kinds of configurations we can set? We could set our username, email. We could type git config –list, and it will list all of our configurations. We’ll see that there’s a lot in there, a lot that we haven’t set yet. These are the system defaults.
Image for post
Image for post

How does Git keep track of our project files?

Image for post
Image for post

When we hit Enter, we will see it comes up and tells us an initialized empty Git repository inside that project.

Image for post
Image for post

If we look over here, we’ll see there’s nothing inside. That’s because of the dot file (the hidden files). The dot files won’t show up by default. If we type ls -alh, the terminal will show all files including the hidden ones in the listing. So now we see a listing of all the files in the directory as well as directories that start with a period. This invisible Git directory is where Git does all of its trackings. Having that directory lets us know that the Git repository has been initialized and is ready for us to use.

Q: What goes inside that directory?

Image for post
Image for post

Let’s go inside that .git directory and explore. We can see that Git is keeping track of HEAD, config, objects, refs. Other new folders and files (shown below) are going to be created inside this .git directory when our project grows over time.

Image for post
Image for post

It depends on the complexity of the project information Git needs to track. The good news is we don’t need to deal with any of these files. Except for maybe the config in some cases.

Image for post
Image for post

If you take a look at that config file at .git/config, you can see that it contains some configuration information.

We could configure some user-level configuration, at the same time, we can also configure our project. And if we did, this file is where Git would store it. And we should leave the rest of it alone and allow Git handles things itself. We don’t really need to go poking around in here very much. What to keep in mind is that this Git directory is all of Git’s tracking. If we were to delete this Git directory, Git would be removed from the project. There would be no tracking information left anywhere on our hard drive once we throw it away.

This directory is tracking. That’s a little different from SVN or Subversion if you’ve used it before. SVN puts little files in every single directory that peppers them out through everything that’s tracking, and if you want to remove SVN from a project, you have to go and dig through the files and remove each and every little files that keep track of things. Git doesn’t work that way. Git centralizes everything into this one directory. The.git directory contains everything that Git is keeping track of this project. And deleting that folder will erase everything Git knows.

Other articles about Git you might like:

Written by

Designveloper is leading software development company in Vietnam. We offer Web development, mobile application, UI/UX Design, VOIP. www.designveloper.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store