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.
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."
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.
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:
- GitHub Desktop
- Sourcetree
- TortoiseGit
- GitKraken
- Git Butler
- And many more: https://git-scm.com/tools/guis
To start practicing Git, let's first open a pre-configured development environment and explore the sample project.
-
Right-click the below button to open the Create Codespace page in a new tab. Use the default configuration.
🪧 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.
-
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
- ✅ Your copy:
-
Wait a moment for Visual Studio Code to load in your browser.
-
In the left navigation tabs, select File Explorer to show the files. Right-click on
src/index.htmland 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! 🧑🚀
Let's start with using Git in the command line interface (CLI). This is the source of all Git functionality and most powerful option.
-
If the integrated terminal is not already available, open it by pressing
Ctrl+Shift+P, then search forView: Toggle Terminaland pressEnter.
-
Show the installed version of Git to verify that it is installed.
git --version
-
Show the Git help documentation.
git --help
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.
-
Set your Git author name.
⚠️ Don't forget to replaceFirstandLast!git config --global user.name "First Last" -
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 replaceme@example.com!git config --global user.email "me@example.com" -
Confirm the changes by viewing the configuration.
git config --global --list
-
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.
