We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies.

We use cookies and other tracking technologies to improve your browsing experience on our site, analyze site traffic, and understand where our audience is coming from. To find out more, please read our privacy policy.

By choosing 'I Accept', you consent to our use of cookies and other tracking technologies. Less

We use cookies and other tracking technologies... More

Login or register
to apply for this job!

Login or register to start contributing with an article!

Login or register
to see more jobs from this company!

Login or register
to boost this post!

Show some love to the author of this blog by giving their post some rocket fuel 🚀.

Login or register to search for your ideal job!

Login or register to start working on this issue!

Engineers who find a new job through WorksHub average a 15% increase in salary 🚀

Blog hero image

Git: Basic Terms and concepts explained

Divya Bhushan 11 May, 2020 | 4 min read

Git basics

Git: Basic Terms and Commands Explained


Get introduced to Git terminologies to get a better grasp at high-level commands

What is Git?

Git is a Versioning tool used to keep a track of different versions of the same piece of data (or a filetype).

It is a distributed version control system (DVCS). Every developer machine acts like both a "node" and a "hub".
Git maintains data integrity and treats every single filesystem change as data.

The basic architecture of git supports parallel code development, or multiple branches.
The initial project itself is based out of a "master" branch.
This promotes efficient feature developments, easy bug fixes, and code reviews.
This results in frequent collaboration of work among peers.

The ideology behind git developed is its "speed", "easy branching and merging", "data integrity", and "larger collaborations".
Git stores your entire project history locally and lets you quickly access older versions of your data.

Git Workflow : The Three States of Git Files

a-3-tier-architecture-of-git-workflow.png

Git stores your work-in-progress in one of the 3 Stages.

A git project, when first initialized (or cloned), makes a ‘working directory’ on your local machine to start editing your source code.

The current state when reviewd and finalized is added using git add to the next Staging Area (Index). An Index saves the current snapshot of your project. Once you review and confirm the changes, your project is finalized and committed to the Local repository using git commit command utility. A commit ensures that the same snapshot of your project exists in all three stages and that they are in sync with each other.

The git status command shows the working tree status and displays in which stage your files are.

Key Git Terms and git Commands

Although git is a VCS, it has its own filesystem architecture to handle source code.
Some popular VCSs that you might have already used are CVS (Concurrent Version Control System), SVN (Apache SubVersioN), ClearCase, and BitKeeper to name a few.
There is a general tendency to compare some of git's terms with those of earlier VCSs, but do not get carried away by how you used these terms.
Git has a different approach.

Repository


This is a local place/hub on your machine where the entire snapshot of your project is stored.
Every minor change is stored and retrievable.
Repository logs can easily be viewed and retrieved, i.e, you can jump to any older state (time-travel in history) of your code.

Working Directory


This is a local working copy of the project’s latest code.

Index (Staging area, Cache)


An Index is the snapshot of your next commit.
It is where the code moves to once you stage or add (git add) the code in the Working directory.
A Staging area is like a cache memory and acts as a middle layer between the working directory (where the code is developed) and the local repository (where the code resides).
This layer gives a quick preview of the project snapshot that you are about to commit. You can still edit (add, modify, or delete) your code in the Index. You could also revert back an older version (state) of a project here.

Commit

A commit is the latest snapshot (state) of a project. commit-snapshot.png

Every commit has a unique commit ID. All commit logs are stored in the local repository.

A commit is a git object that stores the following attributes: commit ID, author name, authored date, and a commit message (header and body).

Branch

A branch is a parallel, independent line of development.

A branch lets you work on the same piece of code in your isolated workspace. Every branch has its own copy of the project history and develops on its own code. They are easily and often merged with each other.

Master

A master is the main default local branch when the project is first created as a git project.

HEAD

A HEAD is the snapshot of the latest commit on every branch. It is a short name or pointer reference to an SHA-1 of a commit ID on each branch. A HEAD always points to the branch’s latest commit (code) and automatically moves forward with each commit to point to the latest commit ID.

Tip: There is a concept of a ‘detached HEAD’ when the branch points to an older commit and not the latest one.

Checkout

This command switches over to the specified branch and displays the current project state as it is in the branch. It also restores the earlier working tree files.

Clone

A clone is a working copy of a remote repository. remoterepository.png

The git clone command downloads the remote repository and creates a working directory on your local machine.

The screenshot shows a local repository — "learn_branching" — that tracks a remote repository with the URL "https://github.com/divyabhushan/learn_branching.git". "origin" is the name for the remote handler to the remote repository.

Conclusion

Refer to git manual pages for a complete list of available commands as — git help -a

To read about a specific command, use git help [command-name]

Originally published on dzone.com

Author's avatar
Divya Bhushan
Technical Content Writer/Trainer/Administrator/Content developer. Skills: Databases, Linux/Unix, Git, DevOps, Python
    git
    html5
    github
    shell scripting
    unix

Related Issues

viebel / klipse-clj
viebel / klipse-clj
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
  • $100
viebel / klipse
  • 1
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
  • $80
viebel / klipse
  • Open
  • 0
  • 0
  • Advanced
  • Clojure
  • $80
viebel / klipse
  • Started
  • 0
  • 2
  • Advanced
  • Clojure
  • $180
viebel / klipse
  • Open
  • 0
  • 0
  • Intermediate
  • Clojure
viebel / klipse
  • Started
  • 0
  • 1
  • Intermediate
  • Clojure
  • $80

Get hired!

Sign up now and apply for roles at companies that interest you.

Engineers who find a new job through WorksHub average a 15% increase in salary.

Start with GithubStart with Stack OverflowStart with Email