Hello World! I'm the GIT in the family😉
Tags: git
Published: 2021-11-29 19:45:45

 **What is Verion Control?**
Version control or source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time.
It keeps track of every modification to the code in a special kind of database. If a mistake is made, developers can turn back the clock and compare earlier versions of the code to help fix the mistake while minimizing disruption to all team members.
Great version control systems facilitate a smooth and continuous flow of changes to the code rather than the frustrating and clumsy mechanism of file locking - giving the green light to one developer at the expense of blocking the progress of others.
Version control software is an essential part of the every-day of the modern software team's professional practices. 

## **SIMPLE GIT COMMANDS EVERY DEVELOPER SHOULD LEARN**
**[Git](https://git-scm.com/)** is a free and open-source version control system, originally created by Linus Torvalds in 2005. Unlike older centralized version control systems such as SVN and CVS, Git is distributed: every developer has the full history of their code repository locally. This makes the initial clone of the repository slower, but subsequent operations such as commit, blame, diff, merge and log dramatically faster.
It also has excellent support for branching, merging, and rewriting repository history, which has lead to many innovative and powerful workflows and tools. Pull requests are one such popular tool that allows teams to collaborate on Git branches and efficiently review each other's code. Git is the most widely used version control system in the world today and is considered the modern standard for software development.
**Note**: To understand this article, visit [Git](https://git-scm.com/) to know more about it.

## **1. Git Init**
The git init command is the first command that you will run on Git. The git init command is used to create a new blank repository. It is used to make an existing project a Git project. Several Git commands run inside the repository, but the init command can be run outside of the repository.
**_Creating the first repository_**
A repository is a directory that contains all the project-related data. There can also be more than one project on a single repository.


`$ git init`

The above command will create an empty .git repository. Suppose we want to make a git repository on our desktop. To do so, open Git Bash on the desktop and run the above command. Consider the below output:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a4eworpnlgqd7zglk4qa.png)
The above command will initialize a .git repository on the desktop. Now we can create and add files on this repository for version control.
To create a file, run the touch command as follows:

`$ touch <file name>
`
To add files to the repository, run the git add command as follows:

`$ git add <file name>`
Note: To learn more about the **git add** command visit **[Git Add](https://www.atlassian.com/git/tutorials/saving-changes)**.
An empty repository .git is added to my existing project. If we want to start version-controlling for existing files, we have to track these files with the **git add** command, followed by a commit.
We can list all the untracked files by **git status** command.

`$ git status
`
Consider the below output:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jg127ibra3sgsh41z7l6.png)
In the above output, the list of all untracked files is displayed by the **git status** command. To learn more about the status command, visit **[Git Status](https://www.atlassian.com/git/tutorials/inspecting-a-repository#:~:text=The%20git%20status%20command%20displays,regarding%20the%20committed%20project%20history.)**.
After tracking our files, we can add our files using the **git add** command.
**

## 2. Git branch
**
Branches are highly important in the git world. By using branches, several developers are able to work in parallel on the same project simultaneously. We can use the git branch command for creating, listing, and deleting branches.
**Creating a new branch:**

`$ git branch <branch-name>
`
This command creates a branch locally. To push the new branch into the remote repository, you need to use the following command:
**Viewing branches:**


`$ git push -u <remote> <branch-name>`

**Deleting a branch:**

`git branch -d <branch-name>
`
To learn more about the **git branch **command, visit **[Git Branch.](https://www.atlassian.com/git/tutorials/using-branches)**

## **3. Git checkout
**
This is also one of the most used Git commands. To work in a branch, first, you need to switch to it. We use git checkout mostly for switching from one branch to another. We can also use it for checking out files and commits.

`git checkout <name-of-your-branch>
`
There are some steps you need to follow for successfully switching between branches:

- The changes in your current branch must be committed or stashed before you switch
- The branch you want to check out should exist in your local
**There is also a shortcut command that allows you to create and switch to a branch at the same time:**

`git checkout -b <name-of-your-branch>
`
This command creates a new branch in your local (-b stands for the branch) and checks the branch out to new right after it has been created.
To learn more about the **git checkout** command, visit **[Git Checkout](https://www.atlassian.com/git/tutorials/using-branches/git-checkout)**.
**

## 4. Git commit
**
This is maybe the most-used command of Git. Once we reach a certain point in development, we want to save our changes (maybe after a specific task or issue).
Git commit is like setting a checkpoint in the development process which you can go back to later if needed.
We also need to write a short message to explain what we have developed or changed in the source code.

`git commit -m "commit message"
`
To learn more about the **git commit** command, visit **[Git Commit.](https://www.atlassian.com/git/tutorials/saving-changes/git-commit)**
**NB: Git commit saves your changes only locally.**
**

## 5. Git push
**
After committing your changes, the next thing you want to do is send your changes to the remote server. Git push uploads your commits to the remote repository.

`git push <remote> <branch-name>
`
However, if your branch is newly created, then you also need to upload the branch with the following command:

`git push --set-upstream <remote> <name-of-your-branch>
`
or

`git push -u origin <branch_name>
`
To learn more about the **git push** command, visit **[Git Push](https://www.atlassian.com/git/tutorials/syncing/git-push)**.
**NB: Git push only uploads changes that are committed.**
_Remember, the more you use git, the more comfortable you’ll… git with it. (I couldn’t resist.)_