Introduction
This article provides an overview of Git, a distributed version control system that allows local work and branching without needing centralized permissions. It details Git commands, categorizing them into high-level (user-friendly) and low-level (system-focused) commands, and explains key terms like 'repo,' 'commit,' 'index,' and 'remote.' The article also highlights important concepts such as the acyclic graph structure of Git and best practices like frequent commits and the use of squashing to simplify commit history.
What is GIT?
Git is a distributed version control system, VCS. Instead of the traditional centralized control system where even checking out a file required admin privileges, git allows any work to be locally and may diverge as much as you want.
Commands in GIT
In Git, commands are divided into high level ("Porcelain") and low level ("Plumbing") commands. High level commands are designed to be user-friendly and are what you use to interact with Git. Low level commands are more for Git itself and are designed to be used by other tools.
Key Terms
repo: a git tracked project.
working directory: the files you see in your computer.
commit: a point in time representing the project in its entirety. The SHA that represents a commit, 40 a-f 0-9 characters, is calculated from the contents of change, author, time and more
index: used interchangeably with "stage". The index is where you place changes you want to commit.
From Github blog: The Git index is a critical data structure in Git. It servers as the
staging area
between the files you have on your filesystem and your commit history. when you rungit add
, the files from your working directory are hashed and stored as objects in index, leading them to bestaged changes
squash: to take several commits and turn it into one commit. Technically a squash would be taking
N commits
and turning it intoN-1 or 1 commit
, but typically itsN commits
to1 commit
.work tree | working tree | main working tree: the directory where you are working. The files you see in your computer.(Your git repo). Your working tree is setup by
git init
orgit clone
.untracked files: files that are not tracked by git. They are not in the index, and they are not in the commit history.
indexed/staged: this is where the changes are to be committed. You must stage before you commit and you stage changes by using
git add
command.tracked files: files that are already tracked by git. A file could be tracked AND have staged changes (changes stored in the index) ready to be committed.
remote: the same git repo on another computer or directory. You can accept changes from or potentially push changes too.
Key Facts About GIT
git is an acyclic graph.
in git, each commit is a node in the graph, and each pointer is the child to parent relationship. Meaning you can have more than one parent, but you cannot have a child that is also a parent(cycle in the graph).
if you delete untracked files, they are lost forever. commit early, commit often, you can always change history to make it one commit (Squashing)