Installing Git + GitHub Desktop and Working with Them

Featured image

This article explains how a beginner can install Git and start working with it through GitHub.

📖 Contents ⬇️

Contents

This article does not cover Git technology and its capabilities in detail. For that, there is the official book and many other resources.

Installing Git

Download the installer from https://git-scm.com/:

Downloading the installer for Windows

Figure 1: Downloading the installer for Windows

Do not be afraid of unclear explanations you may encounter during installation.

Start the installation:

Installer welcome screen

Figure 2: Installer welcome screen

Choosing the Git installation path

Figure 3: Choosing the Git installation path

Besides the default settings, I personally enable daily checks for Git updates and support for Windows Terminal. You can leave them unchecked:

Choosing installation settings

Figure 4: Choosing installation settings

Choosing the Start Menu folder

Figure 5: Choosing the Start Menu folder

When working with Git, you sometimes need to launch a text editor from the Git console. Here you can choose which text editor will open. If you have nothing special, choose the regular Notepad option Use Notepad as Git's default editor. I have Visual Studio Code Insiders installed, so I choose the option highlighted in blue:

Choosing a text editor for Git

Figure 6: Choosing a text editor for Git

Previously, the initial branch in Git was called master. On GitHub it is now called main, because master historically refers to slaveholders. Choose main as the initial branch name:

Choosing the initial branch name

Figure 7: Choosing the initial branch name

Next comes the choice of how Git will be called from the command line. Leave the default so that Git works everywhere but does not overwrite standard Windows console commands:

PATH configuration

Figure 8: PATH configuration

If you are not familiar with SSH and do not want to customize anything, choose the default:

SSH configuration

Figure 9: SSH configuration

Again, the standard SSL settings will suit us:

SSL configuration

Figure 10: SSL configuration

In Windows, lines in text documents end with two characters \r\n, while in Linux they end only with \n. This causes problems when the same text documents are processed on different operating systems. Since we are installing on Windows but still want standard Git behavior, lines will enter Git with \n at the end. In short, leave everything as default:

Configuring line endings for commits

Figure 11: Configuring line endings for commits

We will run Git Bash in the native MinTTY emulator (it is convenient, for example, when working with OpenSSL for some tasks). That is, leave the default again:

Configuring the terminal for Git Bash

Figure 12: Configuring the terminal for Git Bash

Leave the behavior of the git pull command (downloading a remote repository to the local machine) unchanged:

Choosing Git pull behavior

Figure 13: Choosing Git pull behavior

Also take the default Git user authentication system:

Choosing a credential helper

Figure 14: Choosing a credential helper

In the additional settings, leave everything as default again (do not enable experimental features if the corresponding window appears):

Choosing additional settings

Figure 15: Choosing additional settings

Installation progress

Figure 16: Installation progress

Finishing the installation

Figure 17: Finishing the installation

Git is now installed on your computer, and you can work with it fully through the console. But we want to work together with GitHub, so let us move on to it.

Creating a GitHub Account

GitHub and Git are different things. GitHub is a website where you can host projects using Git, plus various GitHub extras.

So, go to https://github.com/ and follow the Sign up link:

GitHub home page

Figure 18: GitHub home page

Creating a new account has become much simpler than it used to be.

Enter your email, password, username, and country:

Entering Email

Figure 19: Entering Email

When you choose a name for your account, be careful. This step is important! Your future employers may see that name.

After that, you will need to confirm account creation by entering a code sent to your email:

Entering the code

Figure 20: Entering the code

Then sign in with your username and password (or via Sign in on the home page):

Signing in to an existing account

Figure 21: Signing in to an existing account

And now you are in your profile:

Signed in to an existing account

Figure 22: Signed in to an existing account

Creating a New Repository

A repository is a project in Git terminology. Create a new repository via the plus sign:

Creating a new repository

Figure 23: Creating a new repository

Only the project name is required (Latin letters). In the example I named it Test. Everything else is optional:

Project settings

Figure 24: Project settings

Although the rest is optional, I will describe each item under a spoiler:

Repository parameter descriptions

Description — an optional description of your project. It helps with project search.

For example, I typed plot in the GitHub search, and in the search results I can immediately read a short description of each project:

Project settings

Figure 25: Project settings

Choose visibility — if the project is in Private mode, only you can see it; projects in Public mode are available to everyone. Private projects used to be paid; now they are free.

Add a README — adds a README.md file in Markdown format to your project, where you can describe your project in detail. More details About the repository README file. These are the files you see when you open a project:

Example of a  file

Figure 26: Example of a README.md file

Add .gitignore — adds a .gitignore file to your project. When you work on a project in some environment (PyCharm, Visual Studio, and so on), temporary junk files appear that should not be saved in Git. For example, in Qt a .pro.user file is created automatically on each computer. And in Node.js projects you should not put the node_modules package folder on GitHub, because it is created automatically after the npm i command via the package.json file. To avoid committing all this junk, .gitignore lists patterns of files that will not enter Git. When you check the box, a list of languages appears that will pick the right .gitignore contents for you:

Example of choosing a .gitignore file

Figure 27: Example of choosing a .gitignore file

And the repository https://github.com/github/gitignore or the site https://www.toptal.com/developers/gitignore offer many more .gitignore templates.

Add license — adds a license file to your project. There are many licenses for distributing software. For example, MIT lets you do almost anything with the code but removes any liability from the author. And the GNU GPL license requires those who use your code to make their projects open and free under the GNU GPL as well. You can also write your own license. In short, a license is simply a text file describing what a person may and may not do with your project:

Example of choosing a license

Figure 28: Example of choosing a license

By the way, all three of these files can be added to the project later manually as regular files, so you do not have to choose them now.

So, you clicked the Create repository button, and a repository is created:

New repository

Figure 29: New repository

Note that the repository gets a link of the form:

https://github.com/[Your-username]/[Project-name]

For now the repository is empty (if you did not check Add a README file and the other options). In theory, you can create files here on the GitHub website (there is a blue creating new file link in the screenshot above), but it is better to do that only in extreme cases. We will create all files on the computer where we installed Git.

Installing GitHub Desktop

Again, after installing Git and creating a repository on GitHub, you can already work with the repository using the command line, which you will often have to do. But routine Git work is better done through a proper interface. There are many different programs for that, but we will use the official GitHub Desktop.

Go to https://desktop.github.com/download/ and download the installer:

Downloading the installer

Figure 30: Downloading the installer

Installation is quick but differs from standard installers. On the first screen you will be asked to sign in to GitHub:

Signing in to GitHub

Figure 31: Signing in to GitHub

Then you will be redirected to the browser. If you signed out of your GitHub account, you will need to enter your username and password:

Entering GitHub username and password

Figure 32: Entering GitHub username and password

After that, you will be offered to link your GitHub account with GitHub Desktop:

Authorizing GitHub Desktop

Figure 33: Authorizing GitHub Desktop

After successful authorization, choose the correct email and click the Finish button:

Finishing the installation

Figure 34: Finishing the installation

Open GitHub Desktop

Figure 35: Open GitHub Desktop

Cloning a Git Repository

Now let us clone our repository from the GitHub website to your computer. To do this, go to File → Clone repository…:

Menu item for cloning a project

Figure 36: Menu item for cloning a project

Then select our repository, choose the folder where the repository will be copied, and click Clone:

Choosing a repository to clone

Figure 37: Choosing a repository to clone

That is it. Our project is copied:

Repository in GitHub Desktop

Figure 38: Repository in GitHub Desktop

By the way, here you can switch between different repositories:

Switching between repositories

Figure 39: Switching between repositories

And if you right-click a project and choose Show in Explorer, you will go to your repository folder:

Opening the repository folder

Figure 40: Opening the repository folder

In the folder there will be a hidden .git folder, which you should never touch yourself (if you do not see the folder, hidden files and folders are hidden on your system):

The .git folder in the project

Figure 41: The .git folder in the project

Working with a Project

Now in your repository folder you can do anything (except actions with the .git folder): you can save your project here, create files and folders, delete them, edit them in any program, and so on.

For example, I will create a text file test.txt with the contents:

First line
Second line

And I will add an image image.png:

Test image

Figure 42: Test image

Files in the project folder

Figure 43: Files in the project folder

Go to GitHub Desktop. In the Changes tab you will see the project changes: two new files were added:

Project changes

Figure 44: Project changes

In games you deal with save points. Here such save points are called commits. A commit should have a title and an optional description.

It is better to name commits in English, starting with a verb in the base form. There should be no period at the end of the title. For example, for our case the commit can be named Add first files.

But all these naming rules are optional, and you can name it even I added the first two files or A pillow cannot hide.

In general, the title should explain the changes you made. Enter a title and click the Commit to main button:

Creating a commit

Figure 45: Creating a commit

A commit (save point) will be created and shown in the History tab:

Commit history with the first commit

Figure 46: Commit history with the first commit

But the changes did not appear in the repository on GitHub, because the commit was created only locally. Send it to the server by clicking the Publish branch button:

Sending the commit to the server

Figure 47: Sending the commit to the server

This button is named that way only now, because this is our first commit. Later it will have a different name.

Now the changes appear on the GitHub website in our repository:

Repository on the website with the first commit

Figure 48: Repository on the website with the first commit

Let us make more changes in the project folder. For example, I will create a third text file test2.txt with the contents:

1 + 1 = 2

And I will change the contents of test.txt to the following:

Very first line.
Second line
Third line

That is, I added another file, changed something in one place in another file, and added something elsewhere. Go to GitHub Desktop. You will see the changes. Moreover, in the test.txt file you can see a list of changes: changes occurred in two lines. New lines are marked in green, and deleted lines are marked in red:

New changes

Figure 49: New changes

In the same way, create a new commit, for example with the name Create second test commit.

And in the History section the new commit will appear. Send it to the server by clicking the Push origin button (from now on this button will almost always be named that way):

Sending the commit to the server

Figure 50: Sending the commit to the server

The changes will appear on the website with our repository:

Changes in the repository on GitHub

Figure 51: Changes in the repository on GitHub

That is how you continue to work. Make some changes in the project, create a commit with some name, and send it to the server.

Of course, working with Git is not limited to these actions, but this is the basics.