Git -Version Control System

Dixitujjwal
3 min readAug 23, 2021

--

Git image

What is Git?

Git is an open-source distributed version control system , that allows allows us to track and work together with our team members at the same workspace.

Now let’s understand why it is so important.Suppose you are working on some project and your client asks you to add new functionality in your project, but after implementing those changes your client said that he don’t want these changes , the previous state of project was fine.In this case ,if you don’t use git you have to either keep track of all changes manually, or you have to find and delete that new functionality.In both the cases the task is time consuming.

Git allows us to keep track of the history of our project.It also allows us to revert back to previous state of project , so adding and deleting functionalities becomes easier.

Real life projects generally have multiple developers working in parallel. So a version control system like Git is needed to ensure there are no code conflicts between the developers.

Version Control System

Version control systems are software tools that help software teams manage changes to source code over time.

It tracks changes to a file or set of files over time so that you can recall specific versions later. It also allows you to work together with other programmers.It also helps to compare the earlier versions of the code with an older version to fix the mistakes.

Now let’s discuss some important terminology related to git.

Git Terminology

Repository

Git repository is just a file location where you are storing all the versions of files related to your project. A repository is a collection of source code. It has committed to the project or a set of references to the commits.

Branch

A branch is a version of the repository that diverges from the main working project.A branch is a version of the repository that diverges from the main working project.

Checkout

Checkout is used for the act of switching between different versions of a target entity. git checkout command is used to switch between branches in a repository.

HEAD

HEAD is the representation of the last commit in the current checkout branch.

.Index(Staging Area)

The Git index is a staging area between the working directory and repository.

Clone

Making copy from server. It is used to make a copy of the target repository or clone.

Merge

It simply means combining branches.The git merge command facilitates you to take the data created by git branch and integrate them into a single branch.

Origin

Remote repository from where the project was initially cloned.It is used instead of that original repository URL to make referencing much easier.

Pull

Receive the data from Server (GITHUB).It fetches and merges changes on the remote server to your working directory

Push

Upload local repository to sever. It refers to upload local repository content to a remote repository.

Stashing

It enables you to switch branch without committing the current branch.

Fork

Forking a repository allows you to freely test and debug with changes without affecting the original project.

GIT Commands

Create a local repository: $ git init

Make copy: $ git clone

Adding file to staging area

1. $ git add file //single file

2. $ git add -A //all files

See the status of file: $ git status

Committing the change: $ git commit -m “comment”

Track the changes that have not been staged: $git diff

Track the changes that have staged but not committed: $git diff –-staged

Track the changes after committing a file: $git diff HEAD

Show the objects :$ git show

Commit History: $git log

Display the files that have been modified: $git log –-stat

Display the modification on each line of a file: $ git blame <file-name>

Branching List a branch: $git branch –-list

Create Branch: $git branch [name]

Delete Branch: $git branch -d [name]

Renaming the branch: $git branch -m [old name] [new name]

Git checkout Switch between branch in a repository: $git checkout [branch name]

Create new branch and switch to it: $git checkout -b [branch name]

Merge the branches: $git merge [branch name]

Working on Remote: $git remote -v

Add remote to repository: $git remote add [name] [remote url]

--

--