Git Introduction for Beginner

Hai Nguyen
5 min readFeb 7, 2021

--

Git has become very popular and is now the de-facto for software development versioning control. Even with the wild popularity and clear benefits of such technology, many projects and developers alike do not make use nor know how to leverage the power of git. I would like to create a series of articles in hoping to promote the use of git. First, an introduction of Git to those who don’t know git, second, to share my daily git commands and finally to propose an effective branching model.

In this article, I’d like to start with an explanation of the common git terms.

What is Git?

Git is a distributed version control system (VCS). In other words, Git is a system to track and synchronize changes of files, moreover, its repositories may reside in many locations, providing redundancy and safeguarding of the code.

Git introduction

Why git?

Git makes collaboration easier and allows safe synchronous changes made by multi-users.

Terminology

Repository

A repository is a place where files and change history reside. Git supports distributed repository which means that there are several places that these modifications can be tracked. Normally, there are remote and local repositories, and these synchronize each other.
A local repository is one that reside on local machine. All local commits will reside on this repository before migrating to the remote.

Working Directory

This is a directory containing all project files which can be edited directly by your editor of choice.

Staging Area (or Index Area)

This is a temporary place where changes are placed and will be committed later.

State

Git tracks changes of files by using three states: modified, staged, committed.

A modified file is a file that has been changed but has not yet entered the staging area. In other words, if we create, update or delete a file, this file will change status to modified.

A staged file is a file whose modifications are in the staging area and these modifications are ready for the next commit. In Git, modifications of a file are not committed immediately. They need to go through a process for entering the staging area.

A committed file is a file whose modifications have been persisted into local repository. Later on, these modifications can persist into remote repositories with a push.

A file can be transverse from committed to modified state then to staged and to committed.

File States

Git Commit

Git commit is an object. It contains changes from a single file or many files. A commit has a unique ID called commit hash.

Git commit

Commit Hash

A commit hash is a unique hash code used for the commit ID.

Tag

Tag is like a bookmark for a commit. Ex: I have a commit whose commit hash is ab123f. I can tag the commit as v1.0. Normally, we tag a version number in order to indicate there’s a release cut at the commit.

Branch

A branch contains a collection of commits representing a line of developments. These commits can be the same or different than ones in other branches. Normally, a branch is used for a topic which implements a specific feature or fixes a bug. Example, I’d like to add a search function when pressing F3. I would then create a branch named feature/search_function_f3 to contain the implementation of specified function.

Clone

Clone is an action to retrieve a copy of the files and their commit histories from the remote repository.

Fetch

Fetch is an action to sync from remote to local repository. This action will not merge changes from a local to a working directory.

Merge

Merge is an action to combine changes from a local repository with a working directory. There are times where it is necessary for us to resolve conflicts after merging.

Git fetch & merge

Pull

Pull is an action to sync new commits from remote to local repository and merge into a working directory.

Git pull

Commit

Commit is an action to place your changes into the local repository.

Push

Push is an action to sync your change from local to remote repository.

Checkout

Checkout is an action for switching branches.

Rebase

Rebase is an action to merge one base branch into the current branch and move all commits from the current branch to the top commits from base branch. In essence, this is to revise your git history.

Cherry-pick

Cherry-pick is an action to selectively choose a commit from one branch to current branch.

Configuration

Git provides a variety of configurations to fit your needs from security, characters encoding, etc. One of the most important configurations are username and email. These are mandatory items when committing changes.

Git configuration is categorized into two types, global and local. Global configurations are ones used across your git whereas local configurations are only used in a specific local repository. Normally, global and local configurations are stored in your home folder and a working directory, respectively.

Conclusion

I have gone through some common terminology used in git for those who do not have previous knowledge, hoping that this information was helpful and easy to understand. Did this introduction provide enough information for you about git?

I will continue to post Git Daily Usage and Branching Model in the later posting so come back for more.

--

--

Hai Nguyen
0 Followers

I am a software developer with the passion for reading and writing articles. They are like taking an adventurous trip through life and I enjoy them immensely.