Introduction
This document provides a step-by-step guide on how to create a new folder, initialize it as a Git repository, add a file, commit it with a meaningful message, and push the changes to a new GitHub repository.
Prerequisites
Ensure that Git is installed on your machine. You can download it from git-scm.com.
Create a GitHub account if you do not have one.
Step 1: Create a New Folder
Open Terminal or Command Prompt: Open your terminal (Linux/macOS) or command prompt (Windows).
Create a New Directory: Run the following command to create a new folder and navigate into it:
mkdir my-git-repo cd my-git-repo
Step 2: Initialize the Git Repository
Run the following command to initialize the directory as a Git repository:
git init
Step 3: Create a New File
Create a new file in the directory. You can use a text editor or create a file directly from the terminal. For example:
echo "This is my first file in the Git repository." > myfile.txt
Step 4: Add the File to Staging
Add the newly created file to the staging area with the following command:
git add myfile.txt
Step 5: Commit the Changes
Commit the changes with a meaningful message using the following command:
git commit -m "Initial commit: Add myfile.txt with introductory content"
Step 6: Create a New GitHub Repository
Log in to GitHub: Go to GitHub and log in to your account.
Create a New Repository:
Click on the "+" icon in the top right corner and select "New repository."
Fill in the repository name (e.g.,
my-git-repo
).Optionally, add a description.
Click "Create repository."
Step 7: Add the Remote Repository
Copy the URL of your new repository (it will look like https://github.com/username/my-git-repo.git
) and add it as a remote. Run the following command:
git remote add origin https://github.com/username/my-git-repo.git
Step 8: Push Changes to GitHub
Finally, push your local commits to the GitHub repository with the following command:
git push -u origin master
Summary
You have successfully created a new folder, initialized it as a Git repository, added a file, committed the changes, and pushed them to a new GitHub repository. You can now view your code on GitHub.