Part1 - Introduction to Git (Core Concepts)

Video: https://youtu.be/uR6G2v_WsRA

#Git #GitHub #Version_Control #Best_Practices #IT

🔙 Previous Part | Next Part 🔜

↩️ Go Back

Table of Contents:


A) Introduction to Git

A.1) What is Git?

Git is a type of Version Control System (VCS).
A VCS enables you to record changes to files over time.

These files could be:

|300

However Git works really well with anything that can be consider a text file.

|150

A.2) What are some of the tasks you can perform with Git?

Before learning about repositories, there are two main concepts that we need to understand:

B) Core Concepts

B.1) The Git Commit Graph

Let's start with the Git Commit Graph

Git tracks changes to files over time. It does this by enabling you to take snapshots of files at any time. These snapshots are called "commits".

We can represent these commits with a basic graph.

B.1.1) Creating a Repo and doing commits

Let's imagine we are setting up a new (local) git repository (also known as a repo).

  1. We start with a standard directory on our filesystem.
    For example: a folder called NETAUTO

  2. Once we have git installed, we can turn this directory into a git repo.
    Starting the repo is done with the git init command.

  3. Let's say we add two files to our directory.
    For example F1 and F2

  1. After adding these new files, we decide to take our first snapshot (git commit).

Now that we have our first snapshot, we can always go back to this point, to how these files looked when we took the snapshot.

  1. Let's say we edit F1 (maybe we add some new lines to it),

  2. After our edits, we can capture our new changes to F1 with a second commit.

  3. Let's say we decide to delete F2 and make a 3rd commit without F2.

On our file system, we will only see the updated F1.

But since we have snapshots, we can restore to earlier versions of files.

Note

Later when we learn about branching, we will see how the concept of checking out determines what is inside the file system

  1. Let's say we decide we want F2 back.

Not only we can retrieve deleted files using commits, but also we can restore files to previous versions and undo changes.

Note

Every commit is logged by git. Git will log who made changes and when.
This is very useful on large projects with many contributors. As we work, we change files. When we are ready, we make a commit and save the state of the files at a particular point in time.


Usually, we make a commit when a logical unit of work is done. For example, when we add a "new feature"


B.2) The 3 Conceptual Areas of a Git Repository

Now we continue with, the 3 Areas of a Git Repo.

In git we have 3 logical areas in which we work with our files.

We have:

B.2.1) The Working Tree

The Working Tree is what we see on our filesystem.

When we add, delete and edit files, we do that in the working tree.

B.2.2) The Git History

The git history is equivalent to the commit graph we just saw.

This history is kept in a hidden directory .git

This directory holds an object database and metadata that makes up the repo.

Warning about .git

If we share that .git directory to someone else. That person would have our complete git project and its full history. They would have access to all the versions of files from the commits we made.

B.2.3) The Staging Area

As we are working on our project, we make changes in the working tree. We add, remove and edit files in the working tree.

But there is one more functionality we have not talked about. Git gives us full control over which changes from our working tree we put into our next commit.

For example, maybe we edited those 3 files, F1, F2, and F3.
However, we only want to capture F1 and F3 on our next commit.

The way we get this control is through the Staging Area.

Only the changes in the staging area are put into the next commit.
Note: The staging area is also know as Index.

C) Example: Creating a new repo (using the terminal) ✍️ 🖥️

Now we can learn more about git commands, using the following example

D) 💬 Summary (copy code 🖥️)

E) Coming Next...

Next, we will learn more about git branching and merging, and how to use remote repos.


🔙 Previous Part | Next Part 🔜

↩️ Go Back


Z) 🗃️ Glossary

File Definition
Uncreated files Origin Note
3 Areas of a Git Repo Part1 - Introduction to Git (Core Concepts)
3 Conceptual Areas of a Git Repository Part1 - Introduction to Git (Core Concepts)
branching Part1 - Introduction to Git (Core Concepts)
Device configs Part1 - Introduction to Git (Core Concepts)
database model Part1 - Introduction to Git (Core Concepts)
Documentation Part1 - Introduction to Git (Core Concepts)
Git Part1 - Introduction to Git (Core Concepts)
git commands Part1 - Introduction to Git (Core Concepts)
Git Commit Graph Part1 - Introduction to Git (Core Concepts)
Git Commit Graph Part1 - Introduction to Git (Core Concepts)
merging Part1 - Introduction to Git (Core Concepts)
metadata Part1 - Introduction to Git (Core Concepts)
object database Part1 - Introduction to Git (Core Concepts)
object database Part1 - Introduction to Git (Core Concepts)
object database Part1 - Introduction to Git (Core Concepts)
remote repos Part1 - Introduction to Git (Core Concepts)
repositories Part1 - Introduction to Git (Core Concepts)
Software code Part1 - Introduction to Git (Core Concepts)
staging area Part1 - Introduction to Git (Core Concepts)
staging area Part1 - Introduction to Git (Core Concepts)
Staging Area Part1 - Introduction to Git (Core Concepts)
The Git History Part1 - Introduction to Git (Core Concepts)
The Staging Area Part1 - Introduction to Git (Core Concepts)
The Working Tree Part1 - Introduction to Git (Core Concepts)
Version Control System (VCS) Part1 - Introduction to Git (Core Concepts)
working tree Part1 - Introduction to Git (Core Concepts)
working tree Part1 - Introduction to Git (Core Concepts)
working tree Part1 - Introduction to Git (Core Concepts)
working tree Part1 - Introduction to Git (Core Concepts)
Working Tree Part1 - Introduction to Git (Core Concepts)