Git 101: Why You Even Need a Version Control System and An Introduction to Git

Unlocking the Power of Version Control: A Beginner’s Guide to Git and Its Benefits for Streamlining Your Development Process

Harshit RV
5 min readApr 3, 2023

In the world of software development, keeping track of changes made to your code is crucial. As projects grow more complex and teams become larger, managing code changes becomes increasingly difficult. This is where version control systems come in.

Version control systems are tools that allow developers to track changes made to their code, collaborate with others, and revert to previous versions if necessary.

Here are the top five reasons why version control systems are essential for efficient software development.

1. Versioning:

A version control system keeps track of changes made to your code over time. This means that you can view previous versions of your code, compare versions, and revert to previous versions if necessary.

2. Backup and Recovery:

A version control system provides a backup of your code. If you accidentally delete or lose your code, you can easily recover it from the version control system.

3. Experimentation:

A version control system allows you to create branches and experiment with different versions of your code without affecting the main branch. This allows you to try out new features and ideas without breaking your codebase.

4. Documentation:

A version control system provides a history of changes made to your code, including who made the changes, when they were made, and why they were made. This information can be used for documentation and to understand the development process.

5. Collaboration:

When multiple people work on the same project, it’s essential to keep track of changes made by each person and collaborate efficiently.

A version control system allows multiple users to work on the same project simultaneously, providing a history of changes and ensuring that all changes are tracked and can be reverted if necessary.

While keeping everything in an orderly, concise and well-documented manner, a version control system takes you from this:

to just this :

Introduction to Git

Git, developed by none other than Linus Torvalds, is a popular version control system used by developers worldwide to track changes in their code, collaborate with others, and manage their projects efficiently.

It is a distributed version control system that, as discussed, allows multiple users to work on the same project simultaneously, providing a history of changes and ensuring that all changes are tracked and can be reverted if necessary.

Basic Git Commands

Here are some basic Git commands that you can use to manage your code:

1. git init

The git init command initializes a new Git repository. This command is used when you want to start tracking changes in a project for the first time.

To use this command, navigate to the project directory and type the following command in the terminal:

git init

2. git add

The git add command adds changes to the staging area. This means that Git will track changes to the files you’ve added and include them in the next commit.

To add changes to the staging area, use the following command:

git add file-name

3. git status

The git status command shows the current status of your repository. This command will show you which files have been modified, which files have been staged, and which files haven’t been tracked yet (the ones that weren’t added by git add command).

To check the status of your repository, use the following command:

git status

4. git commit

The git commit command saves changes to the local repository.

This command creates a new commit with the changes you’ve added to the staging area. Commits can be understood as checkpoints. Basically, whenever you feel your code is in a safe position and everything is working as expected, you commit the code to save its state. You can come back to these checkpoints if you ever end up breaking your code while building a new feature or making it faster to run.

To create a new commit, use the following command:

git commit -m "commit message"

5. git log

The git log command shows the commit history of your repository. This command will show you the commit hash (which is the unique ID of each commit), commit message, author, and date for each commit.

To view the commit history, use the following command:

git log

6. git reset

The git reset command is used to undo changes.

As discussed, if you ever end up breaking your code, you can come to the checkpoints you defined.

This command allows you to move the code to a specific commit and discard all changes made after that commit. To use this command, type the following command:

git reset commit-hash

7. git restore

The git restore command is used to restore files from a previous commit. This command will overwrite the current version of the file with the version from the specified commit.

The git restore command is used to discard changes made to your working directory and restore files to their last committed state. This command is useful when you want to undo changes you've made to a file or set of files without creating a new commit.

To use this command, type the following command:

git restore file-name

For example, git restore index.html will discard any changes made to the index.html file and restore it to its last committed state.

These are just a few of the basic Git commands. There are many more commands

In conclusion, a version control system is an essential tool for any software development team. It helps to keep track of changes made to your code, collaborate with others, and revert to previous versions if necessary.

By mastering the basic Git commands like init, add, commit, status, log, reset, restore, and stash, you can take your software development skills to the next level. With this knowledge, you'll be able to collaborate effectively with your team, experiment with new features and ideas, and maintain a well-documented and stable codebase.

Remember, practice makes perfect, so keep working with Git, and you'll soon become an expert in no time!

If you like what I write, consider following me here on Medium and checking out my new newsletter, Synergy by Harshit RV.

You can expect to see deep dives and posts about productivity tools, new AI libraries and how they can be used to make your life easier and more productive and curated content from around the world I find worth sharing.

--

--