CONTENTS
Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. Git is a Distributed Version Control System. So Git does not necessarily rely on a central server to store all the versions of a project’s files. Instead, every user “clones” a copy of a repository (a collection of files) and has the full history of the project on their own hard drive. This clone has all of the metadata of the original while the original itself is stored on a self-hosted server or a third party hosting service like GitHub.
Git helps you keep track of the changes you make to your code. It is basically the history tab for your code editor(With no incognito mode ?). If at any point while coding you hit a fatal error and don’t know what’s causing it you can always revert back to the stable state. So it is very helpful for debugging. Or you can simply see what changes you made to your code over time.
Git also helps you synchronise code between multiple people. So imagine you and your friend are collaborating on a project. You both are working on the same project files. Now Git takes those changes you and your friend made independently and merges them to a single “Master” repository. So by using Git you can ensure you both are working on the most recent version of the repository. So you don’t have to worry about mailing your files to each other and working with a ridiculous number of copies of the original file.
To sum up, a version control system like Git makes our code easy to:
We can say Git stores all this information in a data structure called a Git repository. The repository is the core of Git. To be very clear, a Git repository is the directory where all of your project files and the related metadata resides.
Take a look at git workflow shows below, how changes are saved from working directory to remote repository
Working directory — The working directory contains the set of working files for the repository. You can change and modify the content whenever you want and commit the changes to the repository. Every new commit is going to save in binary format so that the same name of files committed by others will also be saved with another unique binary file name.
Staging area — The staging area is the place to store changes in the working tree before the commit. It’s the middle stage which contains a snapshot of the changes in the working directory for changed or new changes that are relevant to create the next commit and stores their mode like filetype etc.
Local Repository — A repository contains the history, the different versions over time and all different branches and tags. In Git each copy of the repository is a complete repository.
Remote Repository — It is a shared repository hosted in a server where all the collaborators upload changes made to files.
If you consider a file in your Working Directory, it can be in three possible states.
The gragh below shows the different stages of hosting your code changes as well as the basic git commands used to exchange data between them:
git add
is a command used to add a file that is in the working directory to the staging area.git commit
is a command used to add all files that are staged to the local repository.git push
is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository.git fetch
is a command used to get files from the remote repository to the local repository but not into the working directory.git merge
is a command used to get the files from the local repository into the working directory.git pull
is command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch
and a git merge
.Now that we know what Git is and it’s basic terminologies, let’s see how we can place a file under git. We’re going to do it the right way and the difficult way. Without any GUI applications.
Join the newsletter to receive the latest updates in your inbox.