Git is version control. Meaning a way to track changes that happen in a project (directory of files) and save them as versions of the project.

How Does “git” Work

When a git project is initialized in a directory it creates what is called a repository, or a database to store the project. There are 3 steps to adding something to your git repository.

  1. Make changes. Git does not lock your files so you are free to make any changes and the git repository will ignore these changes, or not track them, till you add them.
  2. Add changed files. Adding the files you have changed still does not add those changes to the repository but rather tells Git to add these changed files to the next save you make.
  3. Commit changed files. This will take all the changed files that have been added and save them to your repository as a new version.

This is a great way to save code projects because if something breaks you can go back and look at previous versions to find the change that caused the problem. Git also has branching that allows you to make changes to the repository on a branch and those changes will not affect other branches unless you merge the branches.

This repository is stored locally on the computer it is setup on, meaning if you want to collaborate with multiple people on a project or want to have a backup in case your computer crashes, you will need a central server to track your repository.

Git remote is a way to connect to a server that allows you to upload or download changes to the project using push and pull commands. There are services available to do this for you like GitHub or Bitbucket that have free plans for basic repository use. These services allow for collaboration and create the backup for the repository.


Basic Git Commands to get started

These commands are assuming you have git installed and you are at the top level directory of your project.

git config –global “John Doe”
git config –global

Sets the name and email for all commits made from that machine. Shen tracking changes this makes it is easy to see who made each change.

git init

Creates an empty git repository at the current directory.

git status

Outputs the status of your repository, including files you have added to be committed, files that have not been added, and which branch you are on.

git add src/

Adds the file and its current changes to be saved on the next commit, additional usage for this command.

git add src/

Adds all the files that have been changed within the src directory.

git add -A

Adds all the files within the git project that have been changed.

git commit -m”my commit message”

Saves all the changes that were added. This saves to the git repository on your machine. Every commit must have a message associated to it, by doing -m allows you to add that message.

git clone

Create a new directory called repo, make the directory a git repository and copy all the files from the git repository from the url.

git pull

Pulls the changes from your remote repository down to your local repository.

git push

Push the changes from your local repository up to your remote repository.


Why Do I Care?

Test automation is not like a normal development project. The goal is to get the result of a test to determine if your product is working. Thus you may not care about versions or tracking each change. There are also many automation teams consisting of one person to write the tests, no need for collaboration support.

There is the issue of backing up your code. Although there is plenty of solutions to backup files git does have a built in solution. If you accidentally delete the contents of an entire file, save the changes, and send it to your backup drive. The contents of that file can never be found again. Git keeps a history of all commits or versions ever made on the project. If the contents were deleted and it was not discovered that the deletion was made till a week later, you can still go through all the commits for the last week to find a version of the file before it was deleted.

As the project gets bigger there will be people who are interested how it is working, or offer to add some code to support something like a database connection. Without git you begin a mess of copying files and emailing them back and forth. Email is not a good way to handle files, there will be changes that will get lost. When your tests become so amazing that they add another person to the automation team, email will not be an option.When you have more than 15 or 20 (UI, selenium) tests you will find that they take a long time to run; wishing they would run on a different computer instead of your own. There are solutions that allow for running your tests on the cloud using build servers but they will need access to the code to run the tests. Using git remote in conjunction with GitHub or Bitbucket, while providing a great solution for backups, is an excellent way for the build server to access the code.