Learning to use Git Version Control

Basics of Git

What is Git?

Git is used to track different versions of files. It is useful for group projects, ensuring that everyone can work on it without overwriting each other. Think of it as the tracker of the multiverse versions of your files; it can manipulate the timelines.

Why Learn it?

  1. It makes it a lot easier to keep track of changes between people.
  2. Easy to back up
  3. You can rollback changes that broke something

Essential Git Concepts

Repository (Repo)

A project folder that Git watches. It contains all the files in your project and their histories. Can be local or put on remote platform like GitHub/GitLab.

Commits

A commit is a snapshot that you make of committed files at a specific point in time. The basic structure of a commit contains:

  • unique identifier (hash)
  • timestamp/author
  • commit message describing what was changed (VERY IMPORTANT)

You can think of them as saves in the video game that can go back to.

Branches

Branches work exactly like the parallel universes you see in movies. When you want to work on a major feature (by adding commits), you would typically create a new branch.

Create new branches to:

  • add a new feature
  • fix a lot of bugs
  • experiment with something

There is a bit more specifics of branches later.

Common Workflows

This section describes the general overview of how git would be used without getting into the specifics on commands, those will come later.

Starting a new project

  1. Create a repo on GitHub
  2. Clone it to your computer (follow instructions it shows you)
  3. Add your files
  4. Commit and push changes to remote repo

Working on existing project

  1. Clone repo
  2. Create a new branch for your feature
  3. Make your changes, commit regularly
  4. Push your branch to remote
  5. Create pull request to merge into master

Best Practices

  1. Commit often, this allows for rolling back changes This is still within reason, like don't commit grammar changes to comments separately
  2. Write clear commit messages Explain what you did so the owner of the repo can tell what's going on
  3. Use branches in a group setting Don't work directly on master, it's only for stable features