Part1 - Introduction to Git (Core Concepts)
Video: https://youtu.be/uR6G2v_WsRA
#Git #GitHub #Version_Control #Best_Practices #IT
🔙 Previous Part | Next Part 🔜
Table of Contents:
A) Introduction to Git
A.0) Recommended References
-
Pro Git book by Scott Chacon
https://git-scm.com/book/en/v2 -
Visual Git Reference by Mark Lodato
https://marklodato.github.io/visual-git-guide
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:
- or anything else really...
However Git works really well with anything that can be consider a text file.
A.2) What are some of the tasks you can perform with Git?
- Take snapshots of files over time
- Restore earlier versions of files from snapshots
- Work on multiple versions of a file in parallel.
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).
-
We start with a standard directory on our filesystem.
For example: a folder called NETAUTO
-
Once we have git installed, we can turn this directory into a git repo.
Starting the repo is done with thegit init
command.
-
Let's say we add two files to our directory.
For example F1 and F2
- 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.
-
Let's say we edit F1 (maybe we add some new lines to it),
-
After our edits, we can capture our new changes to F1 with a second commit.
-
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.
Later when we learn about branching, we will see how the concept of checking out determines what is inside the file system
- 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.
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.
.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.
An object database is a database model in which information is represented in the form of objects (as used in object-oriented programming).
There are many kinds of data models. Some of the most common are:
- Hierarchical DB model
- Relational model
- Network model
- Object-oriented DB model
Read more here: https://www.lucidchart.com/pages/database-diagram/database-models
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 🔜
Z) 🗃️ Glossary
File | Definition |
---|