Git and GitHub Commands
Git and GitHub are powerful tools that help you save your code, track changes, and share your projects online.
This guide will help you understand and use the most common commands β step by step and in simple words.
π§ What is Git and GitHub?β
- Git β A software that helps you track changes in your code on your computer.
- GitHub β A website where you can store your Git projects online and share them with others.
πͺ Step 1: Open Your Project Folderβ
Go to the folder where your project is saved.
Right-click inside the folder and choose "Open Git Bash here"
(or open the terminal in VS Code if you use it).
πͺ Step 2: Initialize Git (Start Tracking Your Project)β
This command tells Git to start watching your folder for changes.
git init
π Note: You only need to run this command once per project.
After this, Git will create a hidden .git folder β that means Git is now working in your project.

πͺ Step 3: Check the Status of Your Filesβ
See which files are new, changed, or ready to be uploaded.
git status
- Red text β new or changed files (not added yet)
- Green text β files ready to be saved (staged)

πͺ Step 4: Add Files to Gitβ
Before saving, you must tell Git which files you want to include.
git add .
β
The . means add all files.
You can also add just one file like this:
git add index.html
Now, if you run git status again β the files should turn green.

πͺ Step 5: Save Your Work (Commit)β
When your files are ready, you can commit them. A commit means saving a snapshot of your project with a small message.
git commit -m "First commit"
π‘ Always write a short message in quotes explaining what you changed.

πͺ Step 6: Push Your Code to GitHubβ
Now itβs time to upload your local project to GitHub so it appears on your GitHub account.
We use the git push command for that.
πΉ What does git push do?β
The git push command sends (or uploads) your saved code changes from your computer to your GitHub repository (online).
β οΈ Before using
git push, make sure you have already connected your local folder to your GitHub repository using
git remote add origin "your-repository-link".If you skip this step, Git will show a warning and your code wonβt be uploaded.

πͺ Step 6.1: Go Back to Your GitHub Repositoryβ
After creating your repository on GitHub, youβll see two sections on the page:
- ββ¦or create a new repository on the command line.β
- ββ¦or push an existing repository from the command line.β
π Choose the second option (push an existing repository) and copy the commands shown there.

πͺ Step 6.2: Run These Commands One by Oneβ
1οΈβ£ Connect your local folder to GitHubβ
git remote add origin "your-repository-link"
This command connects your project folder on your computer to your GitHub repository.
(Replace "your-repository-link" with the actual link of your repo.)
2οΈβ£ Rename your main branch (optional but recommended)β
git branch -M main
Git used to call the main branch master, but now GitHub and most tools use main instead. This command renames it to keep everything consistent.
3οΈβ£ Upload your project to GitHubβ
git push -u origin main
This command actually uploads all your commits (saved changes) to your GitHub repository. Once this runs successfully, your project will appear online π
π‘ Are you doing all these steps for the first time?β
If yes, donβt worry! π
You might see a pop-up window asking you to sign in to your GitHub account.
Simply click on βSign in with your browserβ to continue.
- Click Sign in with your browser

- Then click Authorize Git Credential Manager in your browser.

β After signing in, your code will be uploaded to GitHub!
π― Common Git Commandsβ
| Command | What It Does |
|---|---|
git init | Start a new Git repository (only once) |
git status | Check which files are changed or new |
git add . | Add all files to be saved |
git commit -m "message" | Save your changes with a message |
git remote add origin <url> | Connect your local project to GitHub |
git branch -M main | Rename main branch |
git push -u origin main | Upload code to GitHub |
git pull | Get latest updates from GitHub |
git log | Show all commits done so far |
π Congratulations!β
Youβve learned the basic Git and GitHub commands! Now you can easily upload your projects online and keep track of your work.
Whenever you make changes, just repeat these three commands:
git add .
git commit -m "Updated project"
git push