Until now, we’ve been working with Git locally on our computer.
But what if you want to:
- Back up your project online
- Share your project with classmates or teammates
- Collaborate on the same code
That’s where a Remote Repository (like GitHub) comes in.
Step 1: Create a Repository on GitHub
- Go to GitHub.com
- Click New Repository
- Give it a name (e.g., my-first-git-project)
- Choose visibility - Choose who can see and commit to this repository, select private for now.
- Leave it empty (don’t add README yet if you already have files locally).
- Click Create Repository
Now GitHub gives you a repository URL: https://github.com/username/my-first-git-project.git
You can take this repository url from:
- Click on repository
- Click on Clone
- Click on HTTPS
Step 2: Link Your Local Repo to GitHub
git remote add origin https://github.com/username/my-first-git-project.git
Here:
- remote: connects your local repo to GitHub
- origin: is the default name Git gives to your GitHub repository
Step 3: Push Your Code to GitHub
Send your local commits to GitHub:
git push -u origin main
- push: sends changes to GitHub
- -u: sets "origin main" as the default so next time you can just use git push
- main: is the branch name (sometimes it might be master)
Step 4: Verify on GitHub
- Go back to your GitHub repo page
- Refresh You’ll see your files uploaded
Step 5: Clone a Repository (Other Way Around)
Cloning means making a full copy of a project from GitHub onto your computer.
Steps to Clone a Repo:
- Open the folder on your computer where you want to download the project.
- Example: C:\Projects
- Open Command Prompt / Terminal inside that folder.
- Run the git clone command:
git clone https://github.com/username/project.git
After this, a new folder named project will be created.
Inside it, you’ll find all the project files.
Git also copies the complete history of commits.