6 - Version Control Part 1

Having a history of your code and the ability to go back in time or merge your code with someone else's has transformed the way we work!

Git can sound very complicated, but if you stick to the basics, it's extremely helpful and powerful. At the very least - consider it a backup system to keep your code safe.

What are we learning?

In this lesson we will:

The Lesson


Configuring Git

Use the following commands to setup Git for your computer (replace the text with your information). You only have to do this once per computer.

Initializing a Local Repository

We need to tell the git program that we want to start tracking changes:

Create / Edit Some Files

In order to test this process, let's make an empty file:  touch script.js

Check the Current Status

You can see the current status of your folder any time with:  git status

Staging Changes

When you're ready to make a snapshot in time (called a "commit"), you need to decide which new or updated files will be part of the saved information.

Committing a Snapshot

Now you're ready to create a snapshot! You have to include a message - make it short but meaningful.

Notes:  

Seeing History

You can view a log of all commits with:

Branches

The other major benefit of Git is creating alternate timelines using branches. You should never work directly on the main branch - you should always develop and test on a separate branch and then merge the tested code into the main branch. Let's try it:

Restoring Files

Did you delete a file or change code since the last commit and you want it back?

Deleting Files

If you delete files from the project folder, you need to tell Git to stop tracking them

Reseting to a Previous Commit

To go fully back in time (careful, this is dangerous), you can perform a "hard reset".