A Developer’s Best Friend

Dinushi Dhananjani ♥️ 🇱🇰 - Aug 20 - - Dev Community

Imagine you’re working on a big project with your team. Everyone contributes to the same files, making changes, adding new features, fixing bugs, and keeping track of who did what and when can be confusing and chaotic.

So, how do developers work as a group and contribute to the project while keeping everything organized? We need a place to store our codebase where the whole team can access it.

Every developer would have to handle their code files manually if there wasn’t a VCS like Git. Developers may become frustrated and waste time if they unintentionally overwrite the changes made by another developer.

This is where a version control system like Git comes in handy.

Let’s say, Noha and Liam, two developers, are implementing distinct features on the same file. After completing her work, Nohasaves her edits. Since there was no mechanism to keep track of who made modifications, Liam finished his work in the meanwhile and unintentionally saves it over Noha’s edits. Noha needs to start over because her work has been lost. Git might have prevented this scenario by enabling the two devs to work on their respective features independently.

What is a Version Control System?
One tool that helps developers manage code changes over time is a version control system or VCS. Because it keeps track of all the changes made to the codebase, keeps a history of those changes, and lets the team go back to earlier versions when needed, it makes it possible for numerous engineers to work together on a project.

Why Do Developers Need a Version Control System?
Collaboration

Several developers collaborate on the same codebase in a team setting. Various team members’ contributions can be managed with a VCS without erasing each other’s work

History Tracking

By keeping track of all project modifications, a VCS enables developers to know the project’s past as well as who made what changes and why.

Backup

In the event of a local machine failure, the codebase is safe and recoverable because it is kept in a central repository.

Branches and Merges

Independent work on features or bug fixes can be done by developers by creating branches. The work can be integrated back into the main codebase after it has been finished and tested.

There are many version control systems available, such as Git, Azure DevOps Server, Apache Subversion, and Mercurial. These tools offer various options to help manage and organize your source code effectively.

In this article, I will focus on Git, the most popular version control system and the most widely used open-source option.

Git and How Does Git Work?

Git is a distributed version control system, Git ensures that every developer has a complete local copy of the repository. Because most processes are completed locally, this enables speedier operations. Here’s how Git manages code.

Repository

All of the project’s data, history, and branches are kept in one location — the repository.

Commit

When a developer makes a change, they create a “commit,” which is like a snapshot of the project at that point in time. Every commit is identified by a unique ID and includes a message detailing the changes that were performed.

Branches

To work on various project components without affecting the main source, developers can build branches. A team working on a new feature, for instance, would develop a branch named feature-x. The branch can be merged back into the main branch once the feature is finished.(commonly referred to as main or master)

Let’s say that your group is working on a new website. For various elements like the homepage, login system, and payment gateway, the team may establish separate branches. In a different branch, every developer works on the given feature. The feature is integrated into the main branch, which contains the finished and tested version of the website, after it is ready.

If a bug is discovered in the login system while it is being developed, the responsible developer can address it in the login-system branch and subsequently merge the fixed version into main to guarantee that the bug patch is present in the finished product.

Merge

Combining the modifications from one branch into another is known as a merge. For instance, a developer might merge a feature from the feature-x branch into the main branch once it is finished, including the feature into the main codebase.

Here are some mostly used Git commands
These commands cover the basics of using Git for version control and should help you manage your projects more effectively.

git init
Initializes a new Git repository in your project directory. Use this when starting a new project.

git clone
Clones an existing Git repository from a URL to your local machine.

git status
Displays the status of the working directory and staging area, showing which files have been modified, added, or deleted.

git add
Adds changes in the specified file(s) to the staging area. Use git add . to stage all changes.

git commit -m “commit message”
Records a snapshot of the staged changes, creating a new commit. The commit message should describe the changes made.

git push
Upload your local commits to a remote repository (e.g., GitHub). Use git push origin to push changes to a specific branch.

git pull
Fetches and merges changes from a remote repository to your local branch, keeping your local repository up to date.

git branch
Lists all branches in the repository. Use git branch to create a new branch.

git checkout
Switches to the specified branch. You can also use git checkout -b to create and switch to a new branch in one command.

git merge
Merges the specified branch into the current branch, combining the changes from different branches.

git log
Displays the commit history, showing a list of commits along with their messages, authors, and dates.

git stash
Temporarily saves changes that are not ready to be committed, allowing you to switch branches or work on something else without losing your changes.

git remote add origin
Links your local repository to a remote repository, typically on a platform like GitHub.

GitHub
Version control is handled locally via Git, but GitHub offers an online infrastructure for hosting Git repositories, which facilitates collaboration. Teams may work together on projects, exchange code, and even manage tasks using pull requests and issues. GitHub also offers features like access control, bug tracking, and project management tools, making it an essential tool in modern software development.

Conclusion
In summary, a Version Control System (VCS) like Git is an essential tool for any development team. It makes collaboration easier by enabling several developers to work on the same project at once and makes sure that every change is recorded, giving a thorough history of the project. With a version control system (VCS), you may safely merge changes, work independently, and establish branches to keep your projects organized and avoid problems like overwritten or lost code. These skills are further enhanced by platforms like GitHub, which provide a centralized area for teams to work together, evaluate, and effectively manage their projects. One of the most important steps in creating software projects that are reliable, scalable, and well-managed is integrating VCS into your development process.

. . . .
Terabox Video Player