The Easiest Way to Learn Git and GitHub (With Commands)


The Easiest Way to Learn Git and GitHub (With Commands)

Git and GitHub are essential tools in every developer’s workflow. Git helps you track changes in your code and collaborate with others, while GitHub provides an online platform to store and manage your Git repositories.

Whether you’re just starting out in coding or preparing to join a team, learning Git and GitHub the right way can save you time and prevent costly mistakes.

In this step-by-step guide, you’ll learn how Git and GitHub work and how to use the most important Git commands—without feeling overwhelmed.

What Is Git?

Git is a version control system that helps developers track and manage changes to code over time. It allows you to:

  • Revert to previous versions of your project
  • Work on multiple features simultaneously (branches)
  • Collaborate with others without overwriting code

Git works locally on your machine. You can commit changes, create branches, and experiment freely.

What Is GitHub?

GitHub is a cloud-based platform for hosting Git repositories. It allows you to:

  • Back up your code online
  • Collaborate with others via pull requests
  • Review code and track issues
  • Showcase your work to employers or clients

Think of Git as the engine and GitHub as the interface where collaboration happens.

Step-by-Step Guide to Learn Git and GitHub

1. Install Git

Download and install Git from the official site:
https://git-scm.com

Once installed, check your version:

git --version

2. Set Up Git

Configure your name and email address. These details will be associated with your commits.

git config --global user.name "Your Name"
git config --global user.email "you@example.com"

To verify settings:

git config --list

3. Initialize a Git Repository

Navigate to your project folder in the terminal:

cd path/to/your/project

Then initialize Git:

git init

This creates a hidden .git folder where Git tracks your files.

4. Add and Commit Files

Stage your changes:

git add filename
# Or to add everything:
git add .

Commit your changes with a message:

git commit -m "Initial commit"

5. Create a GitHub Repository

  1. Go to github.com and sign in.
  2. Click on “New Repository”.
  3. Give your repo a name and click Create Repository.

6. Connect Local Git to GitHub

You need to link your local repository with GitHub. Use the URL provided by GitHub:

git remote add origin https://github.com/username/repository.git

Then push your code:

git push -u origin master

If you’re using the main branch instead of master, run:

git push -u origin main

7. Common Git Commands You Should Know

PurposeCommand
Check status of filesgit status
View commit historygit log
Create a new branchgit branch branch-name
Switch branchesgit checkout branch-name
Create and switchgit checkout -b branch-name
Merge a branchgit merge branch-name
Delete a branchgit branch -d branch-name
Clone a GitHub repogit clone https://github.com/user/repo.git
Pull latest changesgit pull origin main
Push changesgit push origin main

Example Workflow (Simple and Practical)

# Create a new project folder
mkdir my-project
cd my-project

# Initialize Git
git init

# Add a file and commit
echo "Hello World" > index.html
git add index.html
git commit -m "Add homepage"

# Connect to GitHub and push
git remote add origin https://github.com/yourname/my-project.git
git push -u origin main

Bonus: Understanding .gitignore

A .gitignore file tells Git which files to ignore (like node_modules, build folders, or credentials).

Example:

node_modules/
.env
dist/

Add it to your project root and commit it as usual.

Final Thoughts

Learning Git and GitHub doesn’t have to be intimidating. Start by understanding the basic concepts and memorizing a few key commands. As you work on more projects, using Git will become second nature.

Start small: track a personal project, create commits regularly, and push it to GitHub. Eventually, you’ll be ready to collaborate with others, manage branches, and handle complex workflows like a professional.


Leave a Comment

Your email address will not be published. Required fields are marked *