Working with Git & GitHub
Tags: git, github, versioncontrol, repository
Published: 2024-01-17 21:06:58

---
title: Working with Git & GitHub
published: true
date: 2024-01-09 15:51:53 UTC
tags: Git, GitHub, versioncontrol, repository
canonical_url: https://ogagaonuta.hashnode.dev/working-with-git-github
---

![Working with Git & GitHub](https://cdn.hashnode.com/res/hashnode/image/upload/v1704818868587/555f7ab6-c8cf-4285-b292-d174b69a6bed.png?w=1600&h=840&fit=crop&crop=entropy&auto=compress,format&format=webp)

## Introduction

In this article, readers will learn how to use Git and GitHub to improve their workflow.

At different points in a creator's life, there could be a series of undoing and redoing. The idea of version control (tracking and managing changes to a file) can help with this, as the creator adds/removes parts of their program. Being conversant with **Git** and **GitHub** will make this possible.

## Table of Content

* [Prerequisite](#prerequisite)
* [What is Git?](#what-is-git)
* [What is GitHub?](#what-is-github)
* [Creating a GitHub Repository](#creating-a-github-repository)
* [Git first steps](#git-first-steps)
    * [Setting your email and name](#setting-your-email-and-name)
    * [Initialising/Cloning a repository](#initialisingcloning-a-repository)
* [GitHub Desktop first steps](#github-desktop-first-steps)
    * [Creating/Cloning a repository](#creatingcloning-a-repository)
* [Creating a `README.md` file](#creating-a-readmemd-file)
* [Understanding Basic Commands (`add`, `commit`, and `push`)](#understanding-basic-commands-add-commit-and-push)
    * [`add`](#add)
    * [`commit`](#commit)
    * [`push`](#push)
* [Conclusion](#conclusion)
    * [Resources](#resources)

## Prerequisite <a name="prerequisite"></a>

To follow along with this article;

- create an account on [**GitHub**](https://github.com/)
- download and install
    - [Git](https://git-scm.com/download), if you prefer to use a CLI (Command Line Interface), or
    - [GitHub Desktop](https://desktop.github.com/), if you prefer to use a GUI (Graphical User Interface).

## What is Git? <a name="what-is-git"></a>

**Git** is a _version control system_ (a system that helps users refer to previous versions of their work, if need be). It is a software that tracks changes made to files. It runs on the command line and is mostly preferred by creators who work on a CLI like Software Engineers, Web Developers, System Administrators, and Programmers.

## What is GitHub? <a name="what-is-github"></a>

**GitHub** is a website that houses _repositories_ (a top-level folder structure containing sub-folders and files). The repositories are stored remotely (on the website), so, users will need a means to work on them locally (on their computers). This is where _Git_ (a CLI) and the _GitHub desktop application_ (a GUI) come into play. The desktop application is usually preferred by non-programmers.

GitHub also allows for collaboration, which makes it useful for networking, and for team members to work together.

## Creating a GitHub Repository <a name="creating-a-github-repository"></a>

Click on the button and follow the steps to create a GitHub repository:

{% cta https://app.tango.us/app/workflow/Creating-a-Repository-on-GitHub-90a4a9d2bf7a469abb606b90f3a2bb96 %} Creating a GitHub Repository {% endcta %}

## Git first steps <a name="git-first-steps"></a>

_Git_ is a software installed and operated locally. You need a way for it to track the remote repository you're currently working with to upload your files to the correct location. To do this, you set your email and name, after which you choose the remote repository to track by initialising or cloning it.

### Setting your email and name <a name="setting-your-email-and-name"></a>

To set up your email and name on Git to match with your GitHub account, run the following command:

```sh-session
git config [--global] user.email "user@email.com"
git config [--global] user.name "first_name last_name"

```

The command in the square brackets is optional and is used to set the email and name globally on your machine. Omitting the `--global` option sets the email and name for only the current repository.

> The optional commands are to be run without the square brackets.

### Initialising/Cloning a repository <a name="initialising-cloning-a-repository"></a>

To create a local repository to track the remote repository, you can either initialise or clone it. To initialise a folder on your machine as a Git repository means to point it to a remote repository. Navigate to the folder you wish to initialise and run this command:

```sh-session
git init

```

{% cta https://www.loom.com/share/4e440cdd9da14cf196af142a490f1757?sid=a8b60a51-ed44-4ffd-8cdc-1d144fdc58f4 %} How to initialise a repository on the terminal {% endcta %}

To clone a remote repository means to copy the folder structure to your local machine. You would need the remote repository URL to clone it.

```sh-session
git clone https://github.com/owner/repo.git

```

{% cta https://www.loom.com/share/d1eb5b132cff493e9629f99eff5a6e9a?sid=d34e6df0-3c6d-4197-aebf-424479dda7d3 %} How to clone a repository on the terminal {% endcta %}

## GitHub Desktop first steps <a name="github-desktop-first-steps"></a>

GitHub Desktop provides users with a GUI, giving non-programmers a way to access GitHub's features. Launch the GitHub Desktop app and sign in to your account.

{% cta https://www.loom.com/share/074bce81681c48318d3a60e48e38edb3?sid=d514592b-7de9-4041-8ea2-d0dce4b31fa7 %} How to configure GitHub Desktop {% endcta %}

### Creating/Cloning a repository <a name="creating-cloning-a-repository"></a>

After signing in to your account on the GitHub Desktop application, creating and cloning a repository can be done with the click of a button.

- Creating a repository

{% cta https://www.loom.com/share/aad2156367fa4d44bbcc21e62ef5c194?sid=df22b463-12a3-4d17-b78e-d322b2cfcfe6 %} How to create a repository on GitHub Desktop {% endcta %}

- Cloning a repository

{% cta https://www.loom.com/share/a07e6fa7cc224abb8528e6e4099e9f75?sid=5373a9cc-336f-4592-a995-cb1011b8e7de %} How to clone a repository on GitHub Desktop {% endcta %}

## Creating a `README.md` file <a name="creating-a-readmemd-file"></a>

A `README.md` file is a file written in _Markdown_ syntax and is used to give information about a repository. Upon creating a repository, the option to initialise a `README.md` file is available, but it can also be created locally. Creating this file is the same as creating any other file but with the name `README` and the file extension `.md`. The name of this file is by convention, as the repository will use any other markdown file for information about the repository if the `README.md` file is unavailable.

> To learn how to write in markdown syntax, check out this [article](https://dev.to/ogagaonuta/how-to-write-markdown-3pj0)

## Understanding Basic Commands (`add`, `commit`, and `push`) <a name="understanding-basic-commands-add-commit-and-push"></a>

After creating/initialising/cloning a repository, you can now create files, make edits, and continue being creative. These files should communicate with GitHub to make use of the version control system, and also for collaboration. There are three basic commands used for this; `add`, `commit`, and `push`.

These operations are available through _point_ and _click_ on the GitHub Desktop application. Git users will have to prefix these commands with the `git` command.

### `add` <a name="add"></a>

The `add` command is the first step and is used to add file(s) that will be included in a project's history.

```sh-session
# To add selected files
git add file_1 file_2

# To add all files
git add .

```

### `commit` <a name="commit"></a>

The `commit` command is the second step and is used to record the changes made to the files that have been added.

```sh-session
git commit -m "A simple descriptive message"

```

### `push` <a name="push"></a>

The `push` command is used to update (publish) the remote repository with all changes made to the local repository.

```sh-session
git push

```

{% cta https://www.loom.com/share/9311728493df4a70bfd598ba84b321d8?sid=def0b4e8-0f99-4392-8531-4f0be1e9962c %} How to add, commit, and push on the terminal {% endcta %}

## Conclusion <a name="conclusion"></a>

As you have seen, using **Git** and **GitHub** is easy and fun. From _creating a GitHub account_, _creating a repository_, _and initialising or cloning_ _a repository_, to the basic `add`, `commit`, and `push` commands, you should now be comfortable using version control with your projects.

### Resources <a name="resources"></a>

For more reading, you can check these out:

- [https://docs.github.com/en/get-started/using-git/about-git](https://docs.github.com/en/get-started/using-git/about-git)

- [https://docs.github.com/en/desktop/overview/getting-started-with-github-desktop](https://docs.github.com/en/desktop/overview/getting-started-with-github-desktop)

- [https://explainshell.com/](https://dev.to/scottw/explain-shell-5blp-temp-slug-1275153)

Visuals have been created using [Tango](https://app.tango.us/) and [Loom](https://www.loom.com/).