version control system (VCS)
Git is the distributed version control system (VCS). Nearly every developer in the world uses it to manage their code. It has quite a monopoly on VCS. Developers use Git to:
Keep a history of their code changes
Revert mistakes made in their code
Collaborate with other developers
Make backups of their code
And much more
command syntax
command <required> [optional]</required>
Arguments in angle brackets <> are mandatory and must be provided when running the command.
Arguments in square brackets are optional and can be included if needed.
Example: Create a new directory in your terminal
mkdir <directory-name></directory-name>
*<directory-name> is a required argument.</directory-name>
RTFM
Read the Fucking Manual
Porcelain Commands
High-Level commands. These are the ones you’ll use the most often as a developer to interact with your code.
Examples of commonly used porcelain commands:
git status
git add
git commit
git push
git pull
git log
Plumbing Commands
Low-Level commands. (Using these will explain how Fit really works; you won’t use these often as a dev)
Examples:
git apply
git commit-tree
git hash-object
Porcelain vs Plumbing Commands
In Git, commands are divided into high-level (“porcelain”) commands and low-level (“plumbing”) commands. The porcelain commands are the ones that you will use most often as a developer to interact with your code. Some porcelain commands are:
git status
git add
git commit
git push
git pull
git log
Don’t worry about what they do yet, we’ll cover them in detail soon. Some examples of plumbing commands are:
git apply
git commit-tree
git hash-object
Git comes with a configuration both at the global and the repo (project) level. Most of the time you’ll just use the ___
global config
A file can be in one of several states in a Git repository. A few important ones include:
untracked: Not being tracked by Git
staged: Marked for inclusion in the next commit
committed: Saved to the repository’s history
What does it mean s when a file is untracked, staged, or committed?
untracked: Not being tracked by Git
staged: Marked for inclusion in the next commit
committed: Saved to the repository’s history
.md
markdown file extension
Markdown is a lightweight markup language that you can use to add formatting elements to plaintext text documents.
How can you tell the status of a file (i.e., determine whether it is untracked, staged, or committed?)
git status
How do you stage a file?
If already in the right directory:
git add
Example:
file: contents.md
git add contents.md
If not in the right directory
#git add <path><filename>
git add /app/main.py</filename></path>
How do you commit a file?
After staging a file: git add <path-to-file | pattern>
you can commit it: git commit -m “your message here”
Example:
If already in the right directory:
git add contents.md
git commit -m “add contents.md”
How do you see recent commits?
What does this do?
git log
It opens in a pager, so you can:
-scroll up and down with arrow keys
-page down with space
-search with /
-quit with q
Note:
-your terminal locks
-you can’t type normal commands
-you have to press q to get back.
How do you see recent commits NOT in a scrollable viewer and only view the last 5 commits
git –no-pager log -n 5
As opposed to git log, git -no-pager log -n 5 only shows the last 5 commits, and prints them directly (no pager)
What are commit hashes derived from?
What else affects the end hash?
commit hashes are derived from their content changes (i.e., the content committed to the repo).
Other stuff that affects the end hash:
-the commit message
-the author’s name and email
-the date and time
-parent (previous) commit hashes
Note: A full git hash is a 40-character hexadecimal number
SHAs
Occasionally you may hear commit hashes referred to as “SHAs”
Why? Git uses a cryptographic hash function called SHA-1 to generate commit hashes
What’s the start hash? What’s the end hash?
When you specify a range of commits, Git needs:
-a start hash
-an end hash
Example:
git log abc123..def456
This means:
“Show commits after abc123 up to and including def456”
So:
abc123 → start (exclusive)
def456 → end (inclusive)
The “end hash” is just:
👉 the commit where you want Git to stop
“end hash” can also mean the most recent commit
Rule of thumb: If you hear “end hash”, mentally translate it to:
“The commit hash that represents where we want to stop.”
Hexadecimal
Base-16 number system
It uses 16 unique digits: 0 through 9 and A through F
It is widely used in computer science, because it provides a more compact, human-readable representation of binary data (base-2) as each hex digit represents exactly 4 bits.
How do you see the contents of a commit without futzing around with the object files directly?
git cat-file -p <hash></hash>
Example:
git cat-file -p 5b21d4f16a4b07a6cde5a3242187f6a5a68b060f
How do you redirect the output (i.e., the output of the contents of a commit) to a temp file?
catfile-command-here > /tmp/catfileout.txt
Example:
git cat-file -p 5b21d4f16a4b07a6cde5a3242187f6a5a68b060f >/tmp/catfileout.txt
grep
global regular expression print
grep searches for patterns and prints the lines that match
tree
Git’s way of storing a directory