Git and GitHub Essentials: Understanding the Basics
Tags: git, github, datascience, data
Published: 2023-05-28 02:39:02

Git is a version control system used to manage and keep track of changes in software code. The changes can be hosted on a web platform i.e. GitHub.

These two tools are essential for developers as changes are made in code daily. A basic introduction to git is well outlined here. To perform actions in git, commands are run in a command-line interface known as Git Bash.

By the end of this article, a beginner should be able to make a commit and upload it onto a remote repository i.e. GitHub.

**These are the basic terminologies used in git:**

1. **Repository(repo)** — a central location where Git stores all the files, folders, and version history of a project.
2. **Remote repository** — a repository hosted on a server or online(web-based) like GitHub where the version history can be saved and interacted with.
3. **Local repository** — a copy of the git repository that resides on the local machine. It contains a git directory(hidden file), commit histories, files, and folders.

There are also some basic commands in git that can be used to make a commit and upload it onto a remote repository — where colleagues can interact with the project. Interaction can be done by analyzing the project and probably making changes and saving the changes made.

Here is a beginner-friendly walkthrough to learn the process of making commits and pushing a project onto a remote repository i.e. GitHub:

**Step 1: Create a folder and save it**

We assume this folder will contain files of our project and our intention is to track the changes we will make to the project and host them on GitHub — where other colleagues can interact with it.

I will name my folder “First_project”. You can add a file of choice including a .txt file.

Close the folder and navigate to Git Bash.

**Step 2: Create a git directory(hidden file) in the saved folder**

To do this, navigate into the folder you have created through the command line by;

```
cd "the_file_path_to_the_folder"
```
In my Git Bash environment, it will resemble this;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uh123cyx41lch5cwfvj4.PNG)

To confirm you are working in the directory, you can use the command;

```
pwd
```
The command prints the current directory.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5yoieuhboix65gshma1.PNG)

In the current directory, create a git repository(hidden file) in the folder. This is done by initializing using a command;

```
git init
```
 
In my command line;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4czssh9d9ywjniyb80u.PNG)

**Step 3: Add the files from the folder that you wish to track**

This is done through a command;

```
git add "name_of_the_file"
```
In my command line;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wncbz5sjzqlbdg5evs2a.PNG)

**Step 4: Check whether the file(s) have been added & ready for commit**

Run a command;

```
git status
```
In my command line;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hw0f796r9w6ik5fxqued.PNG)


To do this, use the command;

```
git commit -m "include_a_message"
```
The message is a short description of why the commit is made.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fznrprcd352famw9ruct.PNG)

**Step 6: Create an empty remote repository on GitHub**

On your GitHub account, create a new repository, where the files will be hosted on the remote repository.

You will be directed to this window after creating the repo successfully;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/21fs0el95805yovldk2s.PNG)

Copy the link displayed, that will be used to create a link between git and the remote repository we created.

**Step 7: Create a connection to the remote repo**

Use the command:

```
git remote add origin <the_link_copied_from_github_repo>
```
On Git Bash:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bw5oucec0k6v639kawsv.PNG)

This creates a connection to the remote repository we created on GitHub.

**Step 8: Push the files to GitHub**

After creating the connection, push the files to the remote repository by;

```
git push -u origin
```
In Git Bash, a successful push command will appear as;

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vviegoarhyl2amx4gvg7.PNG)

The files are now reflected on the remote repository in GitHub. To confirm this, you can open the remote repository on GitHub and view the files [here](https://github.com/John-Maina/first_project)

They will appear as:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jy7z1emjy7qskfiryv58.PNG)

Follow the steps above to track and manage changes in files through git and GitHub.