If you guys quickly search on Google about Git it says that
"Git is a distributed version-control system for tracking changes in source code during software development."
So, What is a Version Control System?
First thing first, try reading "version control" as "control version". A Version Control System (VCS) or also called as Source Code Manager (SCM) is just software that helps you control (or manage) the different versions of something (typically your Source Code).
Git is an SCM (and therefore a VCS!). The URL for the Git website is "https://git-scm.com/" (and you can see how it has "SCM" directly in its domain!).
There are a lot of Version Control Systems:
But, there are two main types of Version Control Systems:
- The Centralized Model - where, all Users connect to a central, master repository.
- The Distributed Model - where, each User has the entire repository on their computer.
Repository / Repo:
A Repository is a directory(folder) which contains your project work, which are used to communicate with Git. Repositories can exist either locally on your computer or as a remote copy on another computer. A repository is made up of commits.
Every time you save (commit) the state of your project in Git, it basically takes a picture of what all your files look like at that moment and stores a reference to that commit. You can think of it as a save point in a game - it saves your project's files and any information about them.
The Working Directory(Folder) are the files that you see in your computer's file system. When you open your project files on a code editor, you're working with files in the Working Directory. This is in contrast to the files that have been saved (in commits) in the repository.
Branch in Git is similar to the branch of a tree. Going back to the example of save point in a game, you can think of a branch as where you make a save point in your game and then decide to try out a risky move in the game. If the risky move doesn't pan out, then you can just go back to the save point. The key thing that makes branches incredibly powerful is that you can make save points on one branch, and then switch to a different branch and make save points there, too.
The Primary(default) branch in Git is the Master or the Main branch.
Staging Area / Staging Index / Index:
A file in the Git directory that stores information about what will go into your next commit. You can think of the staging area as a prep table where Git will take the next commit. Files on the Staging Index are poised to be added to the repository.
Running this command will create a new git repository from scratch. It is also used to initialize the existing project folder as a git repository.
git add :
This command will add the file or files that u specify to the staging area or the index. You can run this command as many times as you need. But, Remember before commiting the files it will keep in the staging area. Instead of listing all file names one by one, you can use "." after "git add" to select all files under the current directory.
git add filenameor
git add .
If you want to see what you have in the Staging Area and ready for commit you can run the command. It will display paths of your tracked and untracked files.So, basically it will display the difference between "git add" and "git commit" command.But, Remember it will not show any commit records or information.
This command will take everything that is in the index for the Staging area and put it into the local repository.The "-m" option, which stands for "message". Writing good commit messages is a skill.
git commit -m "Add files"
When you run this command it will take your local repository that you have created and then push it to the remote repository such as Github.
git push <remote> <branch>
If you want to pull the latest changes from the remote repository to the local repository you can do it using git pull command. This command is mostly useful when you are working in a Team or an Organisation.
git pull <remote>
The git clone command download the existing remote repository on your local computer by specifying the URL of the remote repository.Basically, If you find a program or project that you like on GitHub you can clone it and that will download it in your machine.
git clone https://github.com/userName/repositoryName.git
Let me know what you think about this article, and Git in general. I hope this guide will help you with your learning, and hopefully save your time ? Thank you