Follow along: Using git on the command line

Photo by Jess Bailey on Unsplash

Follow along: Using git on the command line

Step 1: Install Git

If you haven't already done so, you'll need to install Git on your computer. You can download Git from the official website: https://git-scm.com/downloads.

Step 2: Create a New Repository on GitHub

Go to GitHub.com and create a new repository. You can do this by clicking on the "+" icon in the top right corner of the screen, and selecting "New repository" from the dropdown menu. Give your repository a name and a description, and select "Public" or "Private" depending on your preference.

Step 3: Clone the Repository

Now that you've created your repository on GitHub.com, you'll need to clone it to your local machine. To do this, open up your terminal or command prompt and navigate to the directory where you want to store your repository. Then run the following command:

git clone https://github.com/your-username/your-repository.git

Replace "your-username" and "your-repository" with the appropriate values for your repository.

Step 4: Initialize Git

Once you've cloned the repository, navigate to the repository directory and run the following command to initialize Git:

git init

Step 5: Add and Commit Your Changes

Now that you've initialized Git, you can start making changes to your files. Let's say you want to create a new file called "index.html". To do this, run the following command:

touch index.html

This will create a new file called "index.html" in your repository directory. Now you can add this file to Git by running the following command:

git add index.html

This tells Git to track changes to the "index.html" file. Next, you'll need to commit your changes by running the following command:

git commit-m "Initial commit"

This creates a new commit with the message "Initial commit". You can replace this message with whatever message you'd like to describe your changes.

Step 6: Make Changes and Commit Again

Let's say you want to make some changes to the "index.html" file. Open the file in your text editor, make your changes, and save the file. Then, run the following command:

git status

This will show you which files have been modified since your last commit. You should see "index.html" listed as a modified file. Next, run the following commands:

git add index.html

git commit-m "Updated index.html"

This adds the modified "index.html" file to your next commit and creates a new commit with the message "Updated index.html".

Step 7: Push Your Changes to GitHub

Now that you've made some changes and committed them, it's time to push your changes to GitHub. Run the following command:

git push origin main

This pushes your changes to the "main" branch of your repository on GitHub. You may be prompted to enter your GitHub username and password. Once your changes have been pushed, you should see them on your repository page on GitHub.com.

Congratulations! You've successfully used Git to create a new repository on GitHub.com, clone it to your local machine, make changes, commit your changes, and push your changes to GitHub.com.