Sitemap
Decoding Tech

The tech industry decoded — in short stories, examples, interviews, and food for thought. Decoding tech is fostering conversations where all perspectives in tech are represented.

Git & Version Control

5 min readMar 15, 2021

--

As of now, you have learned a lot about programming languages, data types, functions, and algorithms. Now it's time to put everything together and learn about version control & Git.

Press enter or click to view image in full size

Version Control

Have you ever worked on a shared online document on Google Docs, Microsoft Onedrive, or Dropbox? If yes, then you’ve probably seen that these tools are actively saving your changes on the go. And have you seen that there is a revision history tab that keeps track of all your changes? That’s version control!

Version control has become one of the most important aspects of a programmer’s life to protect and manage code bases — because most of the time you are collaborating with others on the same code. Think of it as a system that helps you to control different versions of your code and makes your life easier by tracking all the changes that have been made to the files where your code lives.

There are many different Version Control Systems (VCS) out there, but Git is for sure one of the most popular ones. In the next few minutes, you’re going to learn how to use Git and make your first commit 💪

Git & Github

Just like you might know from Google Docs, Git manages all changes that were made to the source code over time. It allows you to go back to previous versions or manage contributions from different people working on the same codebase. Each commit (a commit is the fundamental unit of Git) is basically a snapshot of what all your local files look like at the moment.

Github is the most commonly used web interface for version control. On Github, you can visualize the Git version control information and collaborate with others. However, there are also many other web interfaces using Git such as Gitlab, BitBucket, etc.

Git terminology

There is specific Git terminology that you need to know before we start with the exercise. Let’s have a brief look at them. 👀

  • Commit: A commit is a saved snapshot of your project.
  • Repository: Or just repo for the badasses among us. 😎 A repo is a directory that contains your project. It is made up of commits. The repo exists both locally on your computer and as a remote copy on Git.
  • Staging Area: Think of it as a pre-step or a rough draft space. It’s a file in the Git directory that stores information about what will go into the next commit.
  • Branch: A branch is a new line of development that diverges from the mainline of development. You can think of it as an experimental detour from your main project without changing anything on your project’s main code. The main branch is by default called master (which might change soon due to its association with slavery).

Your first commit

Enough about theory, let’s start working with Git! 😍

Before we start, make sure you have Git installed (check it out here). We’ll be working from the command line for this exercise. You can open your command line by either typing terminal in your Mac’s spotlight or cmd in your Windows search.

Step 1 — Initialize a local repo

Open your terminal and find your way to the directory where you have your project or where you are going to place it (use the command cd to navigate through your directories in your terminal). Once in the right place, type git init to initialize your local repo. This would look similar to this, with my project called “decoding_tech”

Step 2 — Add a file to your new repo

One very powerful Git command is git status. It shows you the current status of your project and whether there are changes that are not yet committed. I encourage you to run git status after every Git command just to get used to it and get a feeling for how Git works. Let’s do it now, too.

The output tells you on which branch you are (in this case we are on the master branch), and that you have no commits yet. It even gives you advice on what to do next. Let’s follow this advice and create a new file.

Get Corinne Ruckstuhl’s stories in your inbox

Join Medium for free to get updates from this writer.

There are many ways on how to create a new file, choose the one that works best for you. If you use a Mac, you can use e.g. the touch command, if you’re using Windows type cd. > newfile.html and it will create a new blank file. Go ahead and create this new file inside your project. After you’ve done that, run git status again. Here’s my output (I’ve named my new file index.html):

See? Now Git is saying that it found an untracked file but unless you’re going to do something about it, Git won’t care. So let’s change that and add our file to the staging area.

Step 3 — Add the file to the staging area

Remember that we’ve talked about the staging area as a pre-step before committing? That’s what we are doing when we use the command git add. Git add adds a file to the staging area, before being able to commit. You can either run git add . (which adds all your files to the staging area) or git add index.html (which adds the defined file to it). After that, let’s run git status again and see what Git is telling us.

Oh- wait! I think we’re finally ready to commit! See how the new file is staged and Git is telling that these changes can be committed? 😏

Step 4 — Commit your changes

Usually, when we do a commit, we would append a message informing us about the changes we’ve made. This makes it easier in the future to understand what has been changed during the process. So let’s run git commit and append a message (indicated by -m). Don’t forget to run git status afterward.

WELL DONE! 👏You successfully did your first commit! Way to go! 🚀

We hope this exercise gave you a good first impression of how you can work with Git. Git has many more features and is a science for itself. The key here: training, training, training. Try to make yourself used to work with Git — even if it’s only for a small project you’re working on by yourself. It will help you understand Git better each and every time and you’ll see fast progress. Also, check out the resources just below to find some fun and challenging exercises to play around with Git.

Bonus

Another very powerful Git command is git log. Git log lets you view the commit history. Per default, you will see the most recent commit listed first, with details about the SHA (the SHA is a unique identifier of the commit), the author, the date, and the commit message. Git log has a variety of options on what to display. Try out git log --stat for details about the files that were changed or git log --oneline for a single-line viewing option.

Resources

—

Join us!

We are a diverse & inclusive tech community with a common goal — to empower women across industries & inspire them through learning and networking opportunities. Join us in our mission for gender equality in the tech industry in Switzerland.

--

--

Corinne Ruckstuhl
Corinne Ruckstuhl

Written by Corinne Ruckstuhl

Product @Locatee // Diversity & Inclusion with GirlsInTechSwitzerland

Decoding Tech
Decoding Tech

Published in Decoding Tech

The tech industry decoded — in short stories, examples, interviews, and food for thought. Decoding tech is fostering conversations where all perspectives in tech are represented.