Git for Beginners: Basics and Essential Commands

What is Git
Git is a version control system that tracks changes done to file, this is useful when multiple people are working on the same file each one can track their own work and also revert in case anything goes wrong because of any additions in any part of the code
Why Git is Used
Git is used because it allows multiple people to work on the same file each one can track their own work and also revert in case anything goes wrong because of any additions in any part of the code. It helps the coders collaborate and solves the pendrive sharing problem discussed in the previous article. All the people involved in developing the code can work independently of each other without any stress of how to share the changes done.
Git Basics and Core Terminologies
Repository: It is the folder in which the project is stored, this is the folder which gets updated when we change and commit something.
Commit: A commit is a snapshot of changes saved to the repository with a message.
Working directory: The local directory on which the user works is called the working directory.
Staging area: When the files are added using the git add command they are actually residing in the staging area.
Branch: It is an area where people work on bug fixes and features without altering the main code.
Head: A pointer that points to the most recent commit on the repository you are working on .
.gitignore: This is a file created in the working directory that has names of all files and folders that are not to be added in the repository
Main: This is the default development branch of all repositories (previously it was master).
Common Git Commands
Git init
This command is used to initialize git in a working directory on the local machine.
git init
Git status
This command returns which files are tracked, untracked and in the staging area.
git status
Git add
This command is used to add files to the staging area. The command can add specific files or all files depending upon the parameters added at the end of the command.
git add . - adds all files that are present in folder to staging area (excludes files that are mentioned in .gitignore)
git add <filename> - adds only the mentioned file
Git commit
It is used to save the changes to the git repository, we can also add a message along with this command using the -m parameter, the message added cannot be an empty string.
git commit -m “first commit”
Git reset
It removes all file from staging area, if needed only a specific file can also be removed using
Git reset <url>
Git clone
It is used to create a local copy of the project, similar to downloading the project. The git file will be present in the repo which is downloaded and will track changes between the remote version and this local version
git clone <url>
Git pull
It is used to add the changes saved to the main branch or any specified branch
git pull
Git log
This commands displays the history of the repository
git log
Note : The above mentioned commands can be used with different parameters to create variations.



