Git and GitHub beginner's step-by-step guide

 Here's a beginner's step-by-step guide to using Git and GitHub via the command line. This guide assumes you have Git installed on your computer and have created a GitHub account

.


Step 1: Set Up Git

Install Git: Download and install Git from the official website download if you haven't already.

Configure Git: Open a terminal (command prompt on Windows) and set your name and email globally. Replace "Your Name" and "youremail@example.com" with your own information:

  • git bash
    git config --global user.name "Your Name" git config --global user.email youremail@example.com

Step 2: Create a GitHub Account

Go to GitHub (https://github.com) and sign up for a free account if you don't already have one.


Step 3: Create a Repository on GitHub

Log in to your GitHub account.

Click the "+" sign in the upper-right corner and select "New Repository."

Fill in the repository name, and description, choose public or private, and click "Create repository."


Step 4: Clone the Repository

Open your terminal and navigate to the directory where you want to store your project.

Clone your GitHub repository by replacing <username> and <repository> with your GitHub username and repository name:

git bash
git clone https://github.com/<username>/<repository>.git

This command downloads a copy of the repository to your local machine.

Step 5: Make Changes Locally

Create or edit files within the cloned repository directory.

Use git status to check which files have been modified.


Step 6: Stage and Commit Changes

Stage your changes for commit using git add <filename> or git add . to stage all changes.

Commit your changes with a descriptive message

  • git bash
    git commit -m "Add new feature"


Step 7: Push Changes to GitHub

Push your local commits to your GitHub repository:

git bash
git push origin main

Step 8: Create a Pull Request (Optional)

If you're working on a collaborative project, you can create a pull request on GitHub to propose your changes. Visit your repository on GitHub, and click the "New Pull Request" button.

Step 9: Pull Changes from GitHub

If others have made changes to the repository on GitHub, you can pull those changes to your local copy using:

git bash
git pull origin main

This keeps your local copy up-to-date.


Step 10: Explore More Commands

Continue to learn and explore Git and GitHub by using commands like git branch, git merge, and git checkout as needed for branching, merging, and managing your code.