Lesson 2
Gitting Started
In this lesson, you will learn how to install Git, configure your environment, and create your first repository. You will also learn how to use Gitpod to clone the repository, add a 'Hello World' file, commit, and push changes.
Objectives
- Install Git on your local machine
- Configure your Git environment
- Create your first repository on GitHub
- Clone the repository using Gitpod or on your local machine
- Add a 'Hello World' file, commit, and push changes
Installing Git
To install Git on your local machine, follow the instructions for your operating system:
- Windows: Download the installer from https://git-scm.com/download/win and run it.
- macOS: Install Git using Homebrew by running
brew install git
in the terminal. If you don't have Homebrew, you can download the installer from https://git-scm.com/download/mac. - Linux: Install Git using your package manager. For example, on Ubuntu or Debian, run
sudo apt-get install git
in the terminal.
Configuring Your Git Environment
After installing Git, configure your user name and email address by running the following commands in the terminal:
git config --global user.email "your.email@example.com"
These settings will be used for your commit messages.
Creating Your First Repository on GitHub
To create your first repository on GitHub, follow these steps:
- Log in to your GitHub account.
- Click the '+' icon in the top-right corner and select 'New repository'.
- Enter a name for your repository, add a description (optional), and choose whether to make it public or private.
- Initialize the repository with a README file.
- Click 'Create repository'.
Cloning the Repository
You can clone the repository using Gitpod or on your local machine.
- Gitpod: Visit https://gitpod.io/#https://github.com/yourusername/yourrepository and replace 'yourusername' and 'yourrepository' with your GitHub username and repository name. Gitpod will automatically clone the repository and open a new workspace.
- Local machine: Open the terminal and navigate to the directory where you want to clone the repository. Run the following command, replacing 'yourusername' and 'yourrepository' with your GitHub username and repository name:
git clone https://github.com/yourusername/yourrepository.git
- Then, navigate to the cloned repository by running
cd yourrepository
.
Adding a 'Hello World' File, Committing, and Pushing Changes
To add a 'Hello World' file, commit, and push changes, follow these steps:
- Create a new file called
'hello_world.txt'
in the repository. - Open the file and add the text
'Hello, World!'
. - Save and close the file.
- In the terminal, run the following commands to stage, commit, and push the changes:
git add hello_world.txt git commit -m "Add Hello World file" git push
Your changes will now be visible on GitHub.
Exercises
Install Git and Configure Your Environment
Follow the instructions in the Installing Git and Configuring Your Git Environment sections to install Git on your local machine and configure your user name and email address.
Create Your First Repository on GitHub
Follow the instructions in the Creating Your First Repository on GitHub section to create a new repository on GitHub.
Clone the Repository
Choose whether to clone the repository using Gitpod or on your local machine, and follow the instructions in the 'Cloning the Repository' section.
Add a 'Hello World' File, Commit, and Push Changes
Follow the instructions in the Adding a Hello World File, Committing, and Pushing Changes' section to add a 'Hello World'
file to your repository, commit the changes, and push them to GitHub.