Skip to content

Commit

Permalink
Update intro and add terms to know section
Browse files Browse the repository at this point in the history
  • Loading branch information
mrgenius17 committed Jan 21, 2025
1 parent 79b68eb commit e79c74c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/ch2-git.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# What is git?

Git is a version control system (VCS), which means that it saves, compares, and manages changes to files (usually code files) over time.
Git is a distributed version control system (VCS) that helps developers track and manage changes in their code over time. With Git, every time you commit, or save the state of your project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored. Git thinks about its data more like a stream of snapshots. [^1]

This may seem innocuous, but it's actually vital to the development cycle. Virtually all professional code is managed by some VCS, and git is by far the most common.

# Terms to know

- Repository (Repo): A directory or storage space where your project lives, including all files and version history tracked by Git. Your _local_ repository is your project’s history stored on your computer. A _remote_ repository is a version of your project hosted on the internet or network.
- Working Directory: The directory on your local machine where you modify files before tracking them with Git
- Staging Area (Index): A intermediate area between your working directory and repository where changes are prepared for committing. It’s like a draft space, allowing you to review and adjust changes before they become part of the project’s history.
- Commit: A snapshot of your repository at a specific point in time, including all staged changes.
- Branches: branches are parallel versions of your project. They allow you to work on different features or fixes independently without affecting the main project until you’re ready to merge them back.
- Pull request: a pull request is a way to propose changes from one branch to another. It’s a request to review, discuss, and possibly merge the changes into the target branch, and is often used in team collaborations.
- Merge: merging is the process of integrating changes from one branch into another. It combines the histories of both branches, creating a single, unified history.

## Use cases

### Tracking file changes over time

Have you ever been scared to work on your code after completing a feature because you didn't break it? Git fixes this by allowing you to take a snapshot (or "commit") of your code, which you can always go back to by running a single command (`git checkout ...` or `git reset ...`).

Making multiple commits (best practice is a commit for each feature) throughout the progression of a project allows you to revert at any time to any "milestone." You'll never lose your work again[^1].
Making multiple commits (best practice is a commit for each feature) throughout the progression of a project allows you to revert at any time to any "milestone." You'll never lose your work again[^2].

### Working on different versions of your code at the same time

Expand All @@ -20,14 +30,15 @@ By default, git repositories have one branch named `master` or `main`. This is o

### Code collaboration

Branches (or forked repositories on a platform like GitHub) can be used by multiple developers to collaborate on the same code base. Usually, each developer works on their own branch and implements a feature. Once that feature is complete, they *merge* the branch into the `main` or `master` branch.
Branches (or forked repositories on a platform like GitHub) can be used by multiple developers to collaborate on the same code base. Usually, each developer works on their own branch and implements a feature. Once that feature is complete, they _merge_ the branch into the `main` or `master` branch.

### Storing code remotely

Git can be used with platforms like [GitHub](https://github.com) or [GitLab](https://gitlab.com) to manage code stored in the cloud. This is an important part of the modern development cycle.

Typically, a developer creates a branch, implements their feature (or reaches some stopping point), and then commits their changes. After they commit their changes, they *push* it up to the server hosting the main code base so that others can access it.
Typically, a developer creates a branch, implements their feature (or reaches some stopping point), and then commits their changes. After they commit their changes, they _push_ it up to the server hosting the main code base so that others can access it.

For smaller projects, developers may skip the "creating a branch" step and commit new code directly to the `main` branch.

[^1]: Unless you delete or lose the git repository itself, or manually delete commits.
[^1]: https://git-scm.com/book/en/v2/Getting-Started-What-is-Git%3F
[^2]: Unless you delete or lose the git repository itself, or manually delete commits.

0 comments on commit e79c74c

Please sign in to comment.