As you already probably already know if you are a software developer, jumping into serious projects requires something that we call version control. There are multiple tools out there for this job, but by far the most popular one is GitHub. GitHub is the most used version control system for software developers in this day and age, and we can see it as a champion of version control. To explain the simple stuff for beginners, software version control is a system for managing changes in software, or other digital assets, making it easier for multiple developers to collaborate and work on the same project, but on different versions, if necessary. The underlying software of GitHub, that provides the versioning functionality itself is called Git. GitHub is basically a repository that Git uses to store changes in your code. In this article, I will discuss what Git and GitHub are in more detail, show you the basic Git workflow, and the benefits they offer. Git is an open-source, distributed version control software system that was created by Linus Torvalds in 2005. in order to track changes in developer’s source code, and enable developers to revert to previous versions if needed. Git is installed and stored on your ( let’s pretend that you are a developer ) computer, allowing you to work on projects even when you are offline and working on local development environments. This makes Git an ideal solution for distributed development teams that can work on same projects in a 100% remote fashion. As we already now know, GitHub is an online platform for hosting multiple Git repositories that provides a user-friendly interface for managing Git projects, making it easier for teams to collaborate and keep track of changes in the code base itself. GitHub also offers a range of features that go beyond version control, such as bug tracking, project management, and continuous integration and deployment. One of the key benefits of Git and GitHub is their ability to handle multiple developers working on the same project simultaneously. If and when developers make changes to the same file, Git helps to resolve any conflicts that may arise. This is achieved by using a process known as branching, where each developer creates a separate branch of the code base to work on. Once the changes have been made, the branches can be merged back into the main code base, and Git will automatically resolve any conflicts.
Git and GitHub provide a complete history of changes to the code base, allowing developers to easily see how the code has evolved over time, or how it was debugged. This makes it easier to debug problems and understand why certain changes were made. Additionally, GitHub provides a range of tools for reviewing code, such as pull requests and code reviews, which can help you ensure that the code is of highest quality. Git and GitHub are both open-source, which means that the source code is freely available for anyone to use and modify. This has led to a thriving community of developers who contribute to the development of Git and GitHub, making them even better tools for managing version control. Version control systems like Git are essential for any software development team, providing an efficient and effective way to manage changes in the code. Ability to handle multiple people working on the same project, provide a complete history of changes, and offer a centralized repository make them an essential tool for any team working on a large software project. This makes it easy for developers to access the latest version of the code base, regardless of their location. It also makes it easier to manage and maintain the code base, as it is all stored in one central repository.
Let us pretend that you already have a GitHub account, and that Git is installed on your local machine. You have logged into your account and created a new public or private repository for your new project. Now you have to clone this repository to your local machine, so you can continue working on this project. If your OS is Windows, I recommend using Git Bash, that you can install together with downloading Git. Git Bash is a command line tool that will enable you to write and execute UNIX-like commands on your Windows computer, and this is very useful for our Git commands. Let us now, from this point on, demonstrate a basic Git workflow with basic Git commands that you will probably use daily as a software developer:
1) First, clone a repository from GitHub to your local machine:
2) Switch your local environment to cloned repository directory:
3) If you are using only master ( or main ) branch for your project skip this step, if not, create a new branch for your changes:
It is worth noting that this command creates a new branch, and if you only want to switch existing branches then you have to omit the -b part.
4) Make changes, and stage all these changes to the files in the repository ( this is master branch if you are not using different branches for different versions of your project ):
5) Commit the changes with an optional message that describes them:
6) Push the changes to the remote repository on GitHub ( new-branch-name will be master or main if you did not create a new branch ):
7) This step is optional, but I recommend doing it anyway, just to be safe and sound. With this command you check if there are any uncommitted changes left in the staging area of your Git repository. If the area is clean, the system will display a message nothing to commit, working tree clean. This is something that you should always see when you finish your work ( notice the analogy of “tree” and “branches”, different branches are different versions of your project ).
Now we can go the GitHub repository page, and create a pull request to merge all changes into the master / main branch, if we need to. If the pull request is approved, it will be merged, and you can delete your branch since all changes are now integrated in one master branch. There are many more Git commands that can be used to manage code, but this basic workflow is what can get you up and running with Git and version control. Till further notice, happy coding.
Posted on: February 10, 2023
Print article Email article