In this tutorial, we’ll learn beginner-friendly Git commands that everyone should know for uploading a project to GitHub. These commands are easy to remember and use. We’ll walk through each step to help you upload your project to GitHub easily.
Step 1: Initialize Git in Your Project
Open Git Bash (Windows) or your terminal (macOS/Linux).
You can run Git commands in any terminal that supports them.
On Windows, search for Git Bash in the Start menu.
On macOS/Linux, use your terminal.
Navigate to your project folder using:
cd path/to/your/project-folder
Regardless of the terminal (Git Bash, CMD, or IDE terminal), the Git commands remain the same.
Initialize Git in your project:
git init
Step 2: Add and Commit Your Files
Add all files in your project folder to the staging area:
git add .
(Use git add filename to add specific files.)
Check the current status to see the staged files:
git status
Commit the files with a descriptive message:
git commit -m "Initial commit or a description of your changes"
Step 3: Link Your GitHub Repository
- Add your GitHub repository as a remote origin:
git remote add origin https://github.com/your-username/your-repository.git
Step 4: Push to GitHub
- Push your changes to the master branch of your GitHub repository:
git push -u origin master
Extra Git Commands
Check the Current Branch
git branch
Rename the Current Branch to ‘main’
git branch -m main
Create a New Branch
git checkout -b branch-name
Switch to the Master/Main Branch
git checkout master
Undo Changes in Files (Restore Original)
git checkout -- .
To Add New Changes
- After making changes to files, add them to the staging area:
git add filename # To add specific files
git add . # To add all files
Commit the changes with a message:
git commit -m "Your message describing the changes"
Push the changes to the repository:
git push -u origin master