DEV Community

Cover image for What is version control? Why Git & GitHub are so popular?
Aryan Kaushik
Aryan Kaushik

Posted on

What is version control? Why Git & GitHub are so popular?

Hi Folks, thanks for dropping by!

Today, We gonna learn about Version Control, it's use cases and why git and GitHub are so popular among developers.

What is version control?

Version control, also known as source control, is the practice of tracking and managing changes to software code. Version control systems are software tools that help software teams manage changes to source code over time. As development environments have accelerated, version control systems help software teams work faster and smarter. They are especially useful for DevOps teams since they help them to reduce development time and increase successful deployments.

Version Control Examples.png

Purpose of Version Control.

  1. Multiple people can work simultaneously on a single project. Everyone works on and edits their own copy of the files and it is up to them when they wish to share the changes made by them with the rest of the team.
  2. It also enables one person to use multiple computers to work on a project, so it is valuable even if you are working by yourself.
  3. It integrates the work that is done simultaneously by different members of the team. In some rare cases, when conflicting edits are made by two people to the same line of a file, then human assistance is requested by the version control system in deciding what should be done.
  4. Version control provides access to the historical versions of a project. This is insurance against computer crashes or data loss. If any mistake is made, you can easily roll back to a previous version. It is also possible to undo specific edits that too without losing the work done in the meanwhile. It can be easily known when, why, and by whom any part of a file was edited.

Why VCS(Version Control System) is important for Developers?

  1. Enhances the project development speed by providing efficient collaboration,
  2. Leverages the productivity, expedites product delivery, and skills of the employees through better communication and assistance,
  3. Reduce possibilities of errors and conflicts meanwhile project development through traceability to every small change,
  4. Employees or contributors of the project can contribute from anywhere irrespective of the different geographical locations through this VCS.
  5. For each different contributor to the project, a different working copy is maintained and not merged to the main file unless the working copy is validated. The most popular example is Git, Helix core, Subversion, etc .
  6. Helps in recovery in case of any disaster or contingent situation.
  7. It informs us about Who, What, When, and Why changes have been made.

image.png

Branches in the version control system

What is Git & Why it is widely used?

image.png

Git is a version control system used for tracking changes in computer files. It is generally used for source code management in software development.

Git is used to track changes in the source code
The distributed version control tool is used for source code management
It allows multiple developers to work together
It supports non-linear development through its thousands of parallel branches

Features of Git

  • Tracks history
  • Free and open source
  • Supports non-linear development
  • Creates backups
  • Scalable
  • Supports collaboration
  • Branching is easier
  • Distributed development

The Git workflow is divided into three states:

  1. Working directory - Modify files in your working directory
  2. Staging area (Index) - Stage the files and add snapshots of them to your staging area
  3. Git directory (Repository) - Perform a commit that stores the snapshots permanently in your Git directory. Check out any existing version, make changes, stage them and commit.

Download git

This link has details on how to install Git in multiple operating systems: Link

What is Github and why it is so popular?

Untitled (1920 × 700 px) (1).png

GitHub is an online software development platform used for storing, tracking, and collaborating on software projects. It is a cloud-based version control system. It enables developers to upload their own code files and to collaborate with fellow developers on open-source projects. GitHub also serves as a social networking site in which developers can openly network, collaborate, and pitch their work.

In simple words, Github might be considered as a social media which is made for developers where they share their work. it might be any project regarding website development or any design of a website, or some operating systems like Android, Linux, etc.

How To Use Git & Github Effectively

Let us see how to host a local repository on Github, from the very beginning

  • Step 1. Configure your global username and email:

Set your username:


git config --global user.name "FIRST_NAME LAST_NAME"
Enter fullscreen mode Exit fullscreen mode

Set your email address:


git config --global user.email "email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • Step 2. Creating your workspace By creating a new working directory:
mkdir gitrepo

Enter fullscreen mode Exit fullscreen mode

image.png

Next, move into that working directory:

cd gitrepo

Enter fullscreen mode Exit fullscreen mode

image.png

Once inside that directory, you will need to create a sample file to demonstrate Git’s functionality. You can create an empty file with the touch command:

touch file
Enter fullscreen mode Exit fullscreen mode

image.png

  • Step 3. Initializing a Git repository in an existing directory by using the git init command.
git init
Enter fullscreen mode Exit fullscreen mode

image.png

Git will never track new files automatically, so git add is a necessary step when adding new content to a repository that Git has not previously tracked.

git add .
Enter fullscreen mode Exit fullscreen mode

image.png

You now have an actively tracked Git repository. From now on, each of the steps in this tutorial will be consistent with a regular workflow for updating and committing to an existing Git repository.

Creating a commit message:

Each time you commit changes to a Git repository, you’ll need to provide a commit message. Commit messages summarize the changes that you’ve made.

git commit -m "first Commit" -a
Enter fullscreen mode Exit fullscreen mode

image.png

There are two important parameters of the above command. The first is -m, which signifies that your commit message (in this case “Initial Commit”) is going to follow. Secondly, the -a signifies that your commit should include all added or modified files. Git does not treat this as the default behavior, but when working with Git in the future, you may default to including all updated files in your future commits most of the time.

In order to commit a single file or a few files, you could have used:

git commit -m "first Commit" file1 file2
Enter fullscreen mode Exit fullscreen mode
  • Step 3. Sign up for GitHub

image.png

  • Step 4. Create a repository on github

image.png

Copy the Github Repository URL:

image.png

In the Command prompt, add the URL for the remote repository where your local repository will be pushed.

// Sets the new remote
git remote add origin URL

//Verifies the new remote URL
git remote -v
Enter fullscreen mode Exit fullscreen mode

image.png

Once you have a remote configured, you are able to push your code. You can push code to a remote server by typing the following:

git push --set-upstream origin master
// Only for the first time
Enter fullscreen mode Exit fullscreen mode

image.png

There are many more uses of git like Inspecting & comparing code, Sharing & updating code, tracking path changes, rewriting history, etc

Check out Git Cheat Sheet at this link

This Blog was about getting started with git and GitHub. Stay tuned for more amazing blogs.

Do comment your thoughts and suggestions related to the blog and please share if you found it useful.

Top comments (0)