3 min to read
GIT for Beginners
Git - The Open Source Version Control System from Linus Torvalds.
What is GIT
Git is a distributed revision control and source code management system with an emphasis on speed.
Git was initially designed and developed by Linus Torvalds for Linux kernel development.
Version Control System
Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work.
- Allows developers to work simultaneously.
- Does not allow overwriting each other’s changes.
- Maintains a history of every version.
There are two types of VCS :-
- Centralized version control system (CVCS).
- Distributed/Decentralized version control system (DVCS).
Advantages of Git
- Free and open source Git is released under GPL’s open source license.
- Fast and small As most of the operations are performed locally, it gives a huge benefit in terms of speed. Git does not rely on the central server; that is why, there is no need to interact with the remote server for every operation. The core part of Git is written in C, which avoids runtime overheads associated with other high-level languages. Though Git mirrors entire repository, the size of the data on the client side is small.
- Implicit backup
- Security Git uses a common cryptographic hash function called secure hash function (SHA1), to name and identify objects within its database. Every file and commit is check-summed and retrieved by its checksum at the time of checkout.
- No need of powerful hardware In case of CVCS, the central server needs to be powerful enough to serve requests of the entire team. In case of DVCS, developers don’t interact with the server unless they need to push or pull changes.
- Easier branching CVCS uses cheap copy mechanism, If we create a new branch, it will copy all the codes to the new branch, so it is time-consuming and not efficient. Also, deletion and merging of branches in CVCS is complicated and time-consuming. But branch management with Git is very simple. It takes only a few seconds to create, delete, and merge branches.
Basic Workflow of GIT
Step 1. Modify/Add/Delete a file in the working area.
Step 2. Add these files to the staging area to be tracked(same as ade commit)
Step 3. Commit these files in the local repository with a message.
Step 4. Push these changes to remote repository (same as ade mergetrans)
# adds file to the staging area
[bash]$ git add sort.c
# First commit
[bash]$ git commit –m “Added sort operation”
# adds file to the staging area
[bash]$ git add search.c
# Second commit
[bash]$ git commit –m “Added search operation”
Git - Lifecycle
General workflow is as follows ::
- Clone the Git repository as a working copy.
- Modify the working copy by adding/editing files.
- If necessary, we can also update the working copy by taking other developer's changes.
- Review the changes before commit.
- Commit changes. If everything is fine, then you push the changes to the repository.
- After committing, if something is wrong, then you correct the last commit and push the changes to the repository.