Git: Basic Terms and concepts explained
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
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.
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.
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
Related Jobs
Related Articles
Related Issues
- Started
- 0
- 18
- Intermediate
- Submitted
- 1
- 0
- Intermediate
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 TwitterStart with Stack OverflowStart with Email