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:
- SVN
- GIT
- Mercurial
- Bazaar
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.
Git Terminologies / Keywords :
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.Commit:
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.Working Directory:
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:
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.
Some of the Basic but Important Commands of Git:
git init:
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.
Example:git init
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.
Example:git add filename
orgit add .
git status:
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.
Example:git status
git commit:
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.
Example:git commit -m "Add files"
git push:
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.
Example:git push <remote> <branch>
git pull:
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.
Example:git pull <remote>
git clone:
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.
Example: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
Top comments (6)
Wow, I like it. It was full of knowledge and technical commands. One should write a blog like this.
I'm Glad to here that! It was my first Blog. Thanks a lot!!
Great people like you always welcome!
Nice one!
Thanks a lot!!
Thanks a lot! Though I can't understand What language is this!