A Brief Introduction to Version Control, Git, and GitHub
Hello, there.
Are you trying to understand what really version control is and why it is used? In this article, we will discuss about version control, Git, and GitHub.
What is Version Control?
Version control is simply a technique to keep track of changes in a file or a set of files over time. It may also include who changed the file and what content is changed, allowing multiple users to collaborate on the same file simultaneously and merge the changes later.
For example, suppose you are trying to make a website using HTML and CSS. You invited one of your friends to help you with that project. With version control tools like Git and GitHub, you can create a folder, technically called a repository, and simultaneously write code on the same folder.
Why would you want to work with others on the same folder simultaneously?
Yes, you can share your entire code with your friend so that your friend adds his code to your code and shares that updated code with you and you do the same until the project is completed.
But that’s boring, right? That’s why everyone uses version control tools, especially GitHub while working professionally.
In a paragraph below, we will discuss why we need to use version control tools like GitHub.
Why Do We Need To Use Version Control Tools?
1. To Collaborate On a Project
As we discussed earlier, these tools allow us to collaborate on a project. This is especially helpful if you are working in a team. Also, you can make your source code publicly accessible so that others can use your code, add extra features to your project, or fix issues within that project.
2. As a Backup
Version control tools like GitHub provide nice backup and recovery options. Suppose, you have been working on your project for a month and now your computer hard drive is corrupted. That may be a serious issue if there’s no backup. But, if you hosted your in GitHub, you can easily get back all of your code.
3. Reverting an Error
While working on a project, we can get lots of errors. Some of them can be hard to resolve manually. For example, your code was working fine yesterday, and today, your friend made some changes to multiple files of your project which caused multiple errors and your website is not working as expected. In that scenario, you would like to revert to yesterday’s code undoing what your friend has changed.
In such cases, version control tools come in handy.
What is Git?
Git is a popular version control tool that the creator of Linux Linus Torvalds initially developed. It is a free and open-source tool for source code version management and collaboration.
You can learn more about Git on its official website: https://git-scm.com/
What is GitHub?
GitHub is a platform that allows us to host our project, collaborate on the project, track issues, view insights about who contributed how much, frequency of coding, etc.
We can also host static websites made using HTML, CSS, JS, etc. to GitHub through GitHub Pages.
Git vs GitHub
As we discussed earlier, Git is a free and open-source version control tool whereas GitHub is a software built on top of Git that allows us to host and manage our projects using Git.
GitHub has both free as well as paid plans. If you want, you can explore these pricing plans on GitHub
Most Used Git Commands
There are a lot of git commands. But in general, there are a few basic git commands that are used most often. They are listed below:
-
Git init: This command is used to initialize a git repository inside a folder.
-
Git add: This command is used to add changes to the staging area. We can add a single file by specifying its name like git add “file1.txt” or all files like git add .
-
Git commit <message>: This command is used to confirm changes in the local repository. It is used after the git add command
-
Git push: This command is used to send files from the local repository to the remote repository i.e. from your computer to the remote repository such as GitHub.
-
Git pull: This command is the reverse of git push. Meaning, that it is used to get changes from the remote repository to the local repository. For example, if you have changed a file directly from GitHub and now you want that file to automatically change on your computer, then you use this command.
-
Git clone: This command is used to clone an entire repository from GitHub to your local computer so that you can make changes or use it locally.
-
Git branch: We make different branches while working on a project. This command is used to display all the branches in a repository.
-
Git checkout -b <branch_name>: This command is used to create a new branch.
-
Git checkout <branch_name>: This command is used to switch to the already existing branch.
-
Git log: This command is used to display the commit history.
These are some basic git commands. There are many other commands such as git revert, git restore, git merge, git reset, git remote add, git config, git tag, git log, etc. You can learn more about git commands here: https://git-scm.com/docs
Frequently Asked Questions
1. What is version control with Git and GitHub?
Version control is simply a technique to keep track of changes in a file or a set of files over time. Git is the most popular version control tool and GitHub is a platform that allows us to host our project, collaborate on the project, track issues, view insights about who contributed how much, the frequency of coding, etc.
2. What is GitHub used for?
GitHub is a platform used to host our software project, collaborate on the project, track issues, view insights about who contributed how much, the frequency of coding, etc.
3. What does Git stand for?
Git doesn’t have any full form. Instead, Torvalds chose this name sarcastically as git means an unpleasant person in British slang.
Summary: Git is the most used open-source version control tool used to keep track of changes in a file or a set of files over time. It was originally authored by the creator of Linux, Linus Torvalds. I hope you got a general idea about version control using Git and GitHub and got familiar with some basic Git commands.
Published on: Sat Aug 03 2024