📖 Get Git
Description
Git is a powerful version control tool that helps developers manage and track changes in their code. It is free, open-source, and supports Windows, macOS, and Linux. By mastering Git, you can streamline your workflow and collaborate effectively on software projects.
Git has a large community of developers using and supporting the project. As such, there are many resources available around the web to help you learn Git. I recommend you start your journey at the Git website. There you will find links to the technical docs, download links for the software and tutorials and books to learn Git. These are accurate and technical, but may be difficult to understand if you are just starting out. I recommend you begin with the official Git docs and seek additional help as needed. You should also check out the free ebook for Git called Pro Git available from the Git website. Another resource I think beginners might appreciate is from a YouTuber called Coder Coder. She has a video tutorial that explains many of the basics of Git (and GitHub) in an understandable way.
Task
The purpose of this article is to introduce Git, its setup, and its integration with Visual Studio Code (VS Code). You will learn how to configure Git for your development environment and prepare it for use in future assignments.
Core Principles
- Version Control
- Track and manage changes to files over time, enabling collaborative and efficient workflows.
- GitHub Integration
- Leverage GitHub to store code online and enable teamwork on projects.
- Global Configuration
- Set up Git with your username, email, and preferred code editor for seamless use.
Installing Git
Follow these steps to install Git and set up your environment:
- Download and install Git. Versions are available for Windows, macOS, and Linux.
- Download and install GitHub Desktop (optional). This graphical interface is helpful if you are not comfortable with the command line.
Setting Up Git
After installing Git, configure it with your information and preferred editor. Use the terminal in VS Code (Ctrl+`) to execute the following commands:
- Add your name
-
git config --global user.name "<Your Name>"
- Add your email
-
git config --global user.email "<your.email@example.com>"
- Set VS Code as the default editor
-
git config --global core.editor "code --wait"
- Change the default branch name (optional)
-
git config --global init.defaultBranch main
For more information about using the terminals built into VS Code, visit the Integrated Terminal page in the VS Code docs.
Best Practices
- Use Meaningful Commit Messages
- Write clear and concise commit messages to track changes effectively.
- Organize Your Repositories
- Keep your codebase clean and structured for better readability and collaboration.
- Consult Official Documentation
- Use the Git Docs as a primary reference to solve issues and learn advanced features.
Putting It Into Action
To verify your Git installation, start by checking the version of Git installed on your system. Open a terminal or command prompt and type:
git --version
If Git is installed, you will see output similar to this:
git version 2.39.2
If Git is not installed, you will receive an error. Please revisit the installation instructions in the earlier sections.
Once you've confirmed that Git is installed, you can check your configuration settings by typing:
git config --list
This command displays your current Git settings, such as username, email, and editor. Practice creating a new repository locally and syncing it with your GitHub account as described in the course assignment.
Challenge
Create a new local repository, add a sample file, commit your changes, and push the repository to your GitHub account. Make sure your file is accessible via GitHub Pages.
git init
git add .
git commit -m "Initial commit"