
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
- Go to github.com and sign in.
- Click on “New Repository”.
- 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
Purpose | Command |
---|---|
Check status of files | git status |
View commit history | git log |
Create a new branch | git branch branch-name |
Switch branches | git checkout branch-name |
Create and switch | git checkout -b branch-name |
Merge a branch | git merge branch-name |
Delete a branch | git branch -d branch-name |
Clone a GitHub repo | git clone https://github.com/user/repo.git |
Pull latest changes | git pull origin main |
Push changes | git 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.

I’m Shreyash Mhashilkar, an IT professional who loves building user-friendly, scalable digital solutions. Outside of coding, I enjoy researching new places, learning about different cultures, and exploring how technology shapes the way we live and travel. I share my experiences and discoveries to help others explore new places, cultures, and ideas with curiosity and enthusiasm.