Skip to content

Latest commit

 

History

History
161 lines (105 loc) · 6.87 KB

File metadata and controls

161 lines (105 loc) · 6.87 KB

Step 1: Introduction to Git Version Control

You've been working on a project and realized that organizing backups has become difficult. Since everyone shares updates differently, collaborating with them is very confusing.

After some quick searching, you learned about Git. Supposedly, it makes keeping track of changes and collaborating with others easier. It removes the confusion of older methods like file naming conventions, share drives, and emailed copies of files.

Important

This exercise teaches Git usage on a machine with it already installed. If you want to install it on your own computer, we recommend the official Git site for installation guides, since there are many computer configurations.

📖 Theory: What is Version Control?

Version control systems solve common problems developers face when managing code changes over time. Issues like:

  • Backup and Recovery
  • Sandboxed Experimentation
  • Parallel development
  • Locked files
  • File duplication
  • Conflicting changes
  • Team collaboration

If you have ever experienced any of the below situations, you might like Git version control! 😎

  • my-project-final-v2-really3.zip
  • "When did that stop working? I didn't change anything!" (but you know you did)
  • "The file is locked. I'll work on a copy until he gets back on Monday."
  • "Which email had v2 in it? I think the one from last Wednesday."

What is "Git" version control?

Git is a distributed version control system, meaning each developer has a complete copy of the project history. This differs from centralized systems where there is only one copy in a shared location.

This provides advantages like:

  • Working offline - Most operations are processed locally.
  • Increased robustness - Distributed copies act as backups.
  • Flexible workflows - Developer can use their own processes and tooling.

How do I use Git?

Git is an open-source tool built by developers for developers. As such, the community has consistently developed features to cover most needs.

For example, the community has streamlined Git into nearly all development workflows. Here are a few:

  • Command Line Interface (CLI) - The original tool and source of all functionality.
  • Code Editors - Alongside your favorite coding editors/tools. Examples:
    • Visual Studio Code
    • JetBrains IDEs
    • Xcode
    • Emacs/VIM
  • Hosting Services - Centralized Git Hosts, with online editing through the web browser. Examples:
    • GitHub
    • GitLab
    • Gitea
    • Azure DevOps
    • AWS CodeCommit
    • BitBucket
  • Desktop Applications - Friendly graphical interfaces. Examples:

⌨️ Activity: Open the sample project

To start practicing Git, let's first open a pre-configured development environment and explore the sample project.

  1. Right-click the below button to open the Create Codespace page in a new tab. Use the default configuration.

    Open in GitHub Codespaces

    🪧 Note: Typically a GitHub Codespace automatically includes the repository code and all required settings. This is a modified experience so you can practice from scratch.

  2. Confirm the Repository field is your copy of the exercise, not the original, then click the green Create Codespace button.

    • ✅ Your copy: /{{full_repo_name}}
    • ❌ Original: /skills/introduction-to-git
  3. Wait a moment for Visual Studio Code to load in your browser.

  4. In the left navigation tabs, select File Explorer to show the files. Right-click on src/index.html and select Show Preview to see our sample game in action.

    ❗️ Warning: Don't make any changes! We have not added version control yet! 😱


Tip

Feel free to leave the game open and give it more trial-runs as we make changes! 🧑‍🚀

⌨️ Activity 2: Git in the CLI

Let's start with using Git in the command line interface (CLI). This is the source of all Git functionality and most powerful option.

  1. If the integrated terminal is not already available, open it by pressing Ctrl+Shift+P, then search for View: Toggle Terminal and press Enter.

  2. Show the installed version of Git to verify that it is installed.

    git --version
  3. Show the Git help documentation.

    git --help

⌨️ Activity 3: Set your Git identity

Before we can start versioning our game, let's provide Git our identity so it can associate us as the author for any changes.

Warning

Git stores the author name and email in the history, which is visible to anyone with access to the repository. GitHub provides an optional noreply email address that you can enable from your account email settings.

  1. Set your Git username.

    ⚠️ Don't forget to replace First and Last!

    git config --global user.name "First Last"
  2. Set your Git email address. For additional privacy, consider enabling your noreply address in your account email settings to keep your personal email private.

    ⚠️ Don't forget to replace me@example.com!

    git config --global user.email "me@example.com"
  3. Confirm the changes by viewing the configuration.

    git config --global --list
  4. With your Git identity configured, Mona should already be busy checking your work. Give her a moment and keep watch in the comments. You will see her respond with progress info and the next steps.

Tip

You can also change your username and email per project if you have multiple accounts. On an existing project repository, use --local instead of --global.

Having trouble? 🤷
  • Make sure you replace "First Last" and "me@example.com" with your actual information.