Version Control With GitHub: A Guide

Version control with GitHub keeps track of each change that is made to the code in a project, allowing you to revert without losing work.

Reading Time 6 mins

This article on version control with GitHub is part of the Content Collective series, featuring tips and expertise from Flatiron School staff members on topics ranging from program success to the job search. This series is a glimpse of the expertise you can access during your program at Flatiron School.

Have you ever been working on a project and gotten to a point where you wanted to rewind? Perhaps start over from a previous point and go in a different direction? Hitting undo until you get there would work, but then you’d lose all the work that you had. Wouldn’t it be nice if you could go back but still keep all your work? Well … there is for coding!

What is Version Control?

Version control is a system to keep track of each change that is made to the code in a project. 

Many systems can be used for version control. In the Flatiron School Software Engineering program the focus is on using Git and GitHub. Git is the most widely used version control system and is used in conjunction with GitHub. 

Git commands run locally to track each version and change made to a project on your computer. GitHub stores all those changes so that other people can review the changes.

Why Is Version Control Important?

The importance of version control is not just to show you know a new technology but also to show you can manage larger projects in an organized way.

Using version control will be crucial because you will have many people collaborating on the same project and keeping track of all the different code coming into the project in an organized way is essential. It will allow your managers to review your code before integrating it and it will allow your contributors to apply your code to theirs. 

Showing employers that you can organize your code and be able to compartmentalize code into workable sections that can be integrated or reverted will show them that you have the foundations to work in a collaborative environment.

Git Basics

While completing the labs in the Flatiron School Software Engineering program you will become automatic in the basics of Git version control. 

Each submission will be prefixed with git add . , git commit -m “Completed”, git push. These are very good commands to get used to using, and even better to understand what is happening with each command. 

The git add . command takes note of every file that has been changed in the directory and puts them into the staging area. Take note that the period at the end of the command is what signifies ‘all’ the changed files. 

The git commit -m “Completed” command takes those staged files and designates them to be tracked by an identifier.  This allows each newly committed version to be reviewed or reverted back to.  Then, finally, the git push command sends the committed files to the software holding each version, in Flatiron School’s case it is GitHub.

Beyond the Basics

Once you’ve got the basics, it’s helpful to familiarize yourself with additional commands. The deeper Git knowledge you have, the more applicable you’ll be in larger projects with multiple contributors. 

There are several commands you will want to explore to get a greater sense of compartmentalization in Git. They are git branch, git checkout, git merge, and git pull. These commands will help you store commits into a specific section of a project that you are working on.

Git Branch and Git Checkout

There are two ways to use the git branch. The first is to bring up a list of branches that are associated with the project you are working on. The second way includes an argument after the command and creates a new branch that can be worked on. 

For instance, the command git branch new-branch will create a new branch of the project called new-branch.  You can then start working in that branch with the command git checkout. Git checkout also requires an argument to move into whichever branch you want to work on. 

An example of this would be git checkout new-branch. This command would have you working in the branch created by the command git branch new-branch. This will compartmentalize all the code you are working on for a particular feature of an application or website. 

If you have multiple contributors to the project, then the other contributors can review the code before applying it to the main branch of the project. It also allows you to revert the project to a previous state if the new code creates an error. This is extremely helpful when a project has been deployed and you want to integrate a new feature. If the new feature breaks the application, you can return to the main branch to the commit before the integration.

Git Merge and Git Pull

If you are working on a branch of the project that does not have the most updated code of the project you are not going to know if your code will conflict with the updated code. This is where git merge and git pull help. They allow users to see how new code interacts with previous code and how the new code can be integrated with the deployed branch of the project.

To integrate the new code into the project’s main branch, you will want to ensure you are currently in the main branch.  You can check this by running the command git branch. This will give you a list of branches and the one with a * next to it will be the branch you are currently on.  When at the main branch you can take all the new code from another branch. Then, incorporate it into the main branch with the command git merge new-branch.  The argument that the git merge command takes is the name of the branch you want to integrate with the current branch you are on.

In the case that another contributor merged code on the repository stored on Git Hub and you do not have that code in your local directory, then you want to use the command git pull.  This command will take all the code that another contributor added to the repository and integrate it into the branch that you are currently working on.

Final Thoughts

The practice of version control in Git will help you prepare for a professional role. It also will allow an easier transition into the workflow of the position you land. Even in your professional experience, it would benefit you to take the git commands mentioned here and expand on the multitude of git actions that you have access to (https://git-scm.com/docs).  This will help keep your team’s code organized and manageable.  It will also make it much easier to find bugs and fix them.  Being more efficient in your process is a benefit to everyone.

About Joe Milius

Joe Miius is a Software Engineering Technical Coach at Flatiron School. He has previous teaching experience and has been helping Flatiron School students understand coding concepts for 2 years. He loves problem-solving and takes on each new problem or questions a student presents with vigor and curiosity.

Disclaimer: The information in this blog is current as of July 12, 2023. Current policies, offerings, procedures, and programs may differ.

About Joe Milius

More articles by Joe Milius

Related Resources