Getting Started With Git

After viewing the bigger picture of version control, let's get practical and create our own version controlled project! To keep things easier, we won't mix code into it in this post. We'll just use notepad and just text. We will use code in the later posts, but just for the sake of simplicity - code is not the only thing you can version control. As far as I know, if you can put it in a folder on your computer, you can version control it with GIT.

Getting Started

First things first: install GIT if you haven't yet.

Then create a folder anywhere you want, but keep it empty.

We're going to get started with the GIT GUI tool and look at GIT CMD at a later post.

So once you have the new folder created somewhere, open the GIT GUI tool, which should be available to you if you have GIT installed.

GIT GUI

After opening the tool you should see this (as of 09.05.2021) or a similiar version in the future probably:

GITGUI

In the previous post we went over the fact, that all of the information regarding versions is held in a repository, so that is where we're going to start.

A repository is simply a folder, with a ".git" folder inside.

So select "Create New Repository":

GITGUI2

then click "Browse" and find your freshly created folder and press "Create".

GITGUI3

You should now see the above screen. Multiple windows, tons of buttons, some confusion perhaps? Don't worry, let's take it all apart slowly and accurately.

Creating a Repository

If you see the screen as in the previous screenshot, then you have just created your first version controlled repository! Congratulations! 🎉

Let's make sure the repository has a .git folder, so just open your folder/repository and initially it should look like this:

GITGUI4

It's empty?

It's not really empty, because as a convenience, GIT makes the folder it creates to be hidden by default. So just go to the top bar "View" and check "Show Hidden Files" to make it visible! If you can't find the button to do that, I'd suggest googling for "How to make hidden files visible on <operating system>?".

GITGUI5

Now you can also avoid toggling the hidden items for the folder (because you will probably want to enable it again later), by just going to the address bar at the top of the opened folder and adding "/.git" to the folder path.

I won't go into detail about what is being held in this folder, but know that all of the version control info is held here.

GIT GUI

Now switch back to the tool, let's get pratical.

If you push "Rescan" you will notice that nothing happens. It's because our folder is empty. So let's give it something to scan. Create a new .txt file with notepad and write something and save it:

GITGUI6

Now push "Rescan" again and you should see the file show up!

GITGUI7

Cool! So you might have a couple of questions now, I will try my best to answer them:

Why are the changes "Unstaged"?

Once you have changed the contents of a repository (added a new file, like just now), but haven't added the changes as a new version yet, the changes are considered "Unstaged".

Why are the changes "Untracked, not staged"?

Because neither have you added it to the version history, you haven't also even created a draft of the changes. So first you "Stage" changes (you can also imagine it as a rocket, needing Stages to reach space).

What's next?

After adding your changes to a repository, after they are ready (totally up to you) - they have to be Staged.

Staging

At the lower right window of the GIT GUI tool, you see "Initial Commit Message". This means that you have yet to make the first commit, which is a single version update.

Usually you will see "Initial Commit" as the very first commit in the commit history. The repository commit history is blank at the beginning.

A lot of new terms, I know. Let's push some buttons, so it makes more sense.

Time to Commit

In the "Initial Commit Message" window, type any message you'd like to add to your commit, for example: "First commit, added text file."

Then press "Stage Changed", so that your Changed files get Staged and be ready to be Committed, you should see the file move down to the Staged Changes window.

Then press "Commit".

CONGRATULATIONS! 🎉 You have created your first repository, first version update for it and commited it to the version history!

Hopefully it makes just a tiny bit more sense now.