The next tool to set up on your computer is Git. Git is used to provide version control while you code. This article give you a more in-depth look at what Git does and how to configure Git on your computer.

Git Setup for Mac and Windows

The goal of this guide is to teach you what Git is and what it is used for. In addition, we will also give you a step by step guide on how to install Git for both Mac and Windows.

What is Git?

Git is a free and open source distributed version control system, or DVCS, that allows many developers to work on the same project without requiring them to share a common network connection. Basically this means that multiple people can work on the same project without being in the same room/office. To truly understand how Git works and why it is the most popular and widely used version control system in the world, we first must understand what version control is, and the differences between centralized version control and distributed version control.

Version Control:

You can think of version control as how an individiual or group might keep track of the final and most up to date version of a research paper. For example, during the month or so time period you have to write the research paper, you will save it multiple times. On the first save, you might name it something like ResearchPaper.doc. A few days later you decide to do some more work on it and when you finish, you save the file as ResearchPaperNew.doc, then ResearchPaperNewest.doc, and so on. This process of naming it new things each time you update it continues until you are eventually left with twelve different versions of the research paper and a file named NewestFinalVersionResearchPaperMostRecentNEW.doc. For this specific example, this is totally fine, and as much as we hate to admit it, we've all done it at some point. But when it comes to writing programs and developing software, you can see how this could become a huge problem. Developers could be accidently working on the wrong version of a file, they could be fixing a bug that someone else has already fixed, and so on. That's where centralized and distributed version control comes in.

Centralized Version Control:

Centralized version control is where you have a single, central version of the project you are currently working on, usually hosted on a server somewhere where the developers can access it. When one of the developers makes a change to the project or updates it in some way, they commit or send these changes to the server. Once it's sent, the other developers can now see and download the new changes.

Distributed Version Control:

Distributed version control works a bit differently. Instead of relying completely on a single, central version of the project, all of the developers have the ability to clone the project to have full access to the entire history of it on their own hard drives. This means that everytime a developer wants to make a change, they can do it locally on their own hard drive instead of having to connect to the server to make changes. Once the developer is done working, they can commit some or all of their changes at the same time. Not only does this save valuable time and effort, this type of version control is also incredibly useful in those moments when a rollback is needed. For whatever reason it may be, if the server crashes and the entire project is lost, if someone accidently deletes a chunk of critical code, it can be easily restored as all of the developers have a full copy of the project on their local hard drives.

How to install and setup Git

Mac users:

  1. Launch the Terminal application, it can be found in /Applications/Utilities/. Alternatively you can use the Spotlight search tool (the little magnifying glass in the top right of your screen) to search for Terminal. Once Spotlight locates it, click on the result that says Terminal.

  2. When Terminal opens, type in git and press enter.

  3. If you don't already have git installed, a pop-up will appear saying that The 'git' command requires the command line developer tools. Would you like to install the tools now? Click Install and then agree to the Terms of Service when requested.

  4. When the download finishes, the installer will go away on it's own signifying that git is now installed!

Windows users:

This portion of the guide assumes you have already installed a program called Cygwin which allows us access to Bash on Windows. If you have not installed Cygwin and/or don't know what Bash is, please go to our Bash Setup for Mac and Windows Guide and follow the instructions for installing Bash on Windows. Once you complete that you can continue on with this guide.

1. When you installed Cygwin, you downloaded an executable file (.exe) named either setup-x86.exe or setup-x86-64.exe, depending on what version of windows you are running (32-bit or 64-bit). To install Git, we need to run that executable file again. The file will most likely be located in your /Downloads/ folder. If you are unable to locate this file, you can always redownload it from the Cygwin installation page (make sure you select the right one!)
2. Once you've located the executable file or redownloaded it from the website, run it and allow the application to make changes to your computer if you get a pop up asking about this.
3. Click Next until you get to this step where we select packages to install packageInstaller
4. Using the search bar, type in git. Click the plus sign to the left of Devel and locate the package git, then click where it says Skip until you see the highest number (This is the version of the package we are installing, the higher the number, the more recent it is). gitInstaller

5. Using the search bar again, this time type ssh. Click the plus sign to the left of Net and locate the package openssh, then click where it says Skip until you see the highest number. sshInstaller

6. Now that we've selected the necessary packages to install for Git, go ahead and click Next to install them. When it finishes, make sure the two checkboxes are unchecked and click Finish. Git is now ready to be used in Cygwin!