What is Git?

Categories:

Git is a distributed version control system created by Linus Torvalds. It is fast, scalable, and ideal for both small and large projects.
It track changes in computer files, particularly code. Its used in software development, allowing multiple developers to work on different parts of same codebase simultaneously without overwriting each other’s work. Git also allows user to revert to previous version of code incase of issues with current code, to differentiate between two versions of the code.

What is version control?

Version Control is a system that records changes to files or code over time so you can recall specific versions later. It helps teams collaborate, track history, and recover previous versions. There are mainly two types of Version Contol Systems (VCS):

  • Centralized VCS (e.g., SVN): One central server; all changes tracked there.
  • Distributed VCS (e.g., Git): Every developer has a full copy of the project history.

Installing Git

  • Windows: Use Git for Windows installer
  • macOS: Use Homebrew (brew install git)
  • Linux: Use package manager (sudo apt install git)

Basic Git configuration

git config --global user.name "Raw Doe"
git config --global user.email "rawdoe@example.com"

Git terminology

  • Repository (repo): A directory where Git tracks your project. This directory contains:
    • Your project files
    • A hidden .git folder that stores history and metadata

Repositories can be Local repository that is on your machine/laptop or it can be Remote repository that is on Github, Gitlab, Bitbucket etc.

  • Staging Area/Index: A place where you prepare your changes before committing.
    Only files in the staging area will be included in the next commit.
//First add your files using git add
//Example: git add <file name>
git add file.v

This will add file.v to Staging area.

  • Commit: A snapshot of your staged files at a point in time. Think of it like a save point in your project history.
    • Each commit has
      • A unique SHA hash
      • A message
      • Author + timestamp
//First add your files using git add
//Example: git add <file name>

//Syntax: git commit -m "<type your message>"
git commit -m "Add new UVM module"
  • Branch: A pointer to a series of commits. Read Git Branch to understand it in more detail.
    • Common or default branch : main or master
    • Branches are used develop features, fix bugs, Test ideas safely.
//To check your current git branch
git branch

//Output
* main
  feature_abc
  bugfix_abc

Using this command, git will show you all branches in your local repository (example in laptop) and highlights the current branch with an asterisk

  • Clone: A copy of a remote repository.
//Clone a repository
git clone https://github.com/username/repo.git
  • Merge: Git merge is used to combine two branches into one.
//First check your current branch
//git branch will tell you your current branch. Example git branch gives you 'master' as your current branch

git merge feature_branch

//Above command will merge feature_branch into master branch.
  • Push/Pull: Upload/download code to/from remote repositories.



2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *