What A Version Control System (VCS)? Git Vs Github?

A Version Control System (VCS) is a software tool that helps developers track changes to source code or other digital assets and collaborate on projects with other team members. A VCS enables developers to manage different versions of files and directories, make changes to files, and share those changes with other developers.

In Simple Words Version Control System (VCS) is α software that helps software developers to work together and maintain α complete history of their work.

Why do we Use Version Control System (VCS)

Version History: A VCS keeps a history of all changes made to a file or directory, so developers can view previous versions of the code, see who made the changes, and revert to an earlier version if necessary.

Collaboration: A VCS enables multiple developers to work on the same codebase simultaneously without overwriting each other's changes. Developers can merge their changes and resolve conflicts, ensuring the codebase remains stable and functional.

Code Review: A VCS makes it easy for developers to review each other's changes, comment on them, and suggest improvements. This improves code quality and reduces the likelihood of bugs and other issues.

Backup and Recovery: A VCS acts as a backup of the codebase, so if something goes wrong with the code, developers can revert to a previous version of the code and restore it to a working state.

Some popular version control systems are:

  • Git: A distributed VCS that is widely used in the industry. It is known for its speed, flexibility, and scalability.
  • Subversion (SVN): A centralized VCS commonly used in enterprise environments. It is known for its simplicity and ease of use.
  • Mercurial: A distributed VCS that is similar to Git. It is known for its ease of use and performance.

Types of Version Control Systems (VCS)

Centralized Version Control System (CVCS): In a CVCS, a central server stores the codebase, and developers can check out a copy of the codebase from the server to work on. When a developer changes their copy of the codebase, they must commit those changes back to the server. Examples of CVCS include Subversion (SVN) and Perforce.

Distributed Version Control System (DVCS): In a DVCS, each developer has a complete copy of the codebase on their local machine, so they can work on the codebase without needing to be connected to a central server. Developers can make changes to their local copy of the codebase, commit those changes, and then push those changes to a central server or share them with other developers. Examples of DVCS include Git and Mercurial.

Both CVCS and DVCS have their advantages and disadvantages. CVCS is more straightforward to use and easier to manage for smaller teams, but it can be slow and has a single point of failure in the central server. DVCS, on the other hand, is faster and more flexible, but it can be more complex to use, and there may be issues with merge conflicts and data consistency. Ultimately, the choice of VCS depends on the specific needs of the project and the development team.

Git 

Git is a free and open-source distributed version control system (VCS) widely used in software development. It was created by Linus Torvalds, the creator of Linux, in 2005. It has since become one of the most popular VCS tools in the world. Git is a command-line tool that allows developers to manage changes to source code or other digital assets over time. It tracks changes to files and directories, creating a history of different versions of the codebase. Developers can access previous versions of the code, compare changes between versions, and merge changes made by multiple developers. One of the key features of Git is its distributed architecture, which means that each developer has a complete copy of the codebase on their local machine. This allows developers to work offline and collaborate seamlessly with other team members. Git also provides various tools for managing branches, merging changes, and resolving conflicts, making it easy to work on multiple features or bug fixes simultaneously. Software developers widely use git for version control, but it can also be used to manage other digital assets, such as documentation, images, and configuration files. A large and active community of developers supports it.

Git is a popular Distributed Version Control System (DVCS) that offers several advantages over other VCS tools. Here are some of the key advantages of using Git:

  • Speed: Git is designed to be fast and efficient, even with large codebases. Operations such as committing changes, branching, and merging are typically much faster with Git than with other VCS tools.
  • Distributed Architecture: Git's distributed architecture allows developers to work offline and collaborate seamlessly with other team members. Each developer has a complete copy of the codebase on their local machine, which they can work on independently and then merge changes with others later.
  • Branching and Merging: Git makes branching and merging easy, allowing developers to work on multiple features or bug fixes simultaneously. This makes it easier to manage complex codebases and reduces the risk of conflicts.
  • Open Source: Git is an open-source tool with a large and active community of developers contributing to its development. This means that developers can benefit from a wide range of plugins, integrations, and support resources.
  • Security: Git provides several security features, including encryption, authentication, and access control mechanisms. This ensures that the codebase is protected from unauthorized access and that changes made to the codebase are traceable and auditable.
  • Integration: Git can be easily integrated with other development tools and platforms, such as continuous integration and deployment (CI/CD) pipelines, project management tools, and text editors.

Overall, Git's speed, distributed architecture, branching and merging capabilities, open-source nature, security features, and integration capabilities make it a popular and powerful tool for managing codebases and collaborating on software development projects.

Git Vs. GitHub

Git and GitHub are related but different tools.

Git is a distributed version control system (VCS) that allows developers to manage changes to source code or other digital assets over time. It is a command-line tool that tracks changes to files and directories, creating a history of different versions of the codebase. Developers use git to collaborate on software development projects, manage changes to code, and track progress over time.

On the other hand, GitHub is a web-based hosting service for Git repositories. It provides a graphical user interface (GUI) for managing Git repositories and additional features such as bug tracking, project management tools, and wikis. GitHub allows developers to share code and collaborate on software development projects with other developers worldwide. It also provides tools for code reviews, pull requests, and continuous integration and deployment (CI/CD) pipelines.

An example to explain the difference between Git and GitHub

Suppose you are a developer working on a software project with a team of other developers. You decide to use Git as your version control system to manage changes to the codebase. Using Git, you create a local repository on your computer and begin making changes to the code. You commit your changes to the local repository, and Git tracks your changes over time. You can also create branches in Git to work on different features or bug fixes simultaneously and merge the changes into the main codebase when ready.

Suppose you want to share your code with other developers on your team. You could use Git to manually send them your changes, but this can be difficult to use and time-consuming. Instead, you decide to use GitHub to host your Git repository and collaborate with your team. You create a new repository on GitHub and push your local repository to the remote repository on GitHub. Now, other developers on your team can access the codebase on GitHub, make changes, and push their changes back to the remote repository. You can use GitHub's collaboration tools to review and merge the changes made by other developers, manage issues and bugs, and track progress on the project.

GIT LIFE CYCLE

The general workflow is as follows:

  1. You clone the Git repository αs α working copy.
  2. You modify the working copy by adding/editing files.
  3. If necessary, you also update the working copy by tαking other developer's changes.
  4. You review the changes before commit.
  5. You commit changes. If everything is fine, then you push the changes to the repository.
  6. After committing, if you realize something is wrong, then you correct the
  7. last commit and push the changes to the repository.

To configure Git in your project, follow the below steps:

Step 1: Install Git on your computer. You can download it from the official Git website (https://git-scm.com/downloads).

Step 2: Create a new repository for your project. You can either do this locally on your computer or on a remote server using a Git hosting service like GitHub, GitLab, or Bitbucket.

Step 3: Initialize the Git repository in your project directory by running the command Git init in the command line.

cd D:\Project  //Navigate the Project path 
git init  // Git Initialize

Step 4: Configure your Git user information by running the following commands in the command line, replacing the placeholders with your information:

git config --global user.name "Your Name"   //Configure Git User Name
git config --global user.email "[email protected]" //Configure Git User Email

Create a new branch for your project development by running the command git checkout -b <branch-name>

git branch  // Check the current branch you are on by running the command
git checkout -b Dev-branch // Create a new branch by running the command
git branch //  Check the current branch again you will see the new branch QA-branch

Make changes to your project files and add them to the Git staging area by running the command git add <file-name> for each file you want to stage. You can also use Git add . to stage all changes.

git add index.html // Add new File Index.html

git status   // it will show newly added or modified file
On branch Dev-branch
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

      modified:   index.html

Commit your changes to the Git repository by running the command git commit -m "Your commit message". 

Replace "Added New Registration Form" with a brief description of the changes you made.

git commit -m  "Added New Registration Form"  // Commit Change with a Comment For Future Purpose So 
that it will easily remember what is inside this changeset

Push your changes to the remote repository by running the command git push <remote-name> <branch-name>.

Replace <remote-name> with the name of your remote repository (e.g., "origin") and <branch-name> with the name of the branch you want to push.

git push origin Dev-branch // Push changes to remote repository

Pull changes from the remote repository to your local repository by running the command git pull <remote-name> <branch-name>

git pull origin Dev-branch // Pull change of other Developers who are working in project is they made changes

Commit, Pull, Merge, and Push

Commit: In Git; a commit is a snapshot of the changes made to a repository at a particular time. When you make changes to the files in your local repository, you need to stage these changes using the Git add command and then create a commit using the Git commit command. Each commit has a message describing the changes made and a unique hash identifying the commit.

Pull: In Git, pulling is the process of fetching changes from a remote repository and merging them into the local repository. When you collaborate with other contributors on a project, you may need to pull changes others have made before pushing your own changes. Use the git pull command to pull changes from the remote repository into your local repository.

Merge: A merge conflict occurs when there are conflicting changes made to the same lines of code in two different branches that you're trying to merge together. Git cannot automatically merge these changes because it doesn't know which version of the code you want to keep. When a merge conflict occurs, Git will pause the merge process and ask you to resolve the conflict manually.

Push: In Git, pushing is the process of uploading changes made in the local repository to a remote repository. After you have made changes to the files in your local repository and created a commit, you can use the git push command to upload these changes to the remote repository. This makes your changes available to other contributors on the project.

Note:- It's important to carefully review the changes made in the conflicting code and ensure that your final version is correct and functional. 

Thank you for reading, and I hope this blog post has helped provide you with a better understanding of the Version Control System (VCS).