Git vs. GitHub: What's the Difference?
This is a common point of confusion for beginners, so let's make it clear:
- Git is the tool. It's the command-line program installed on your computer that tracks your code's history (e.g.,
git commit
,git branch
). - GitHub is a service. It's a website that hosts Git repositories on the internet. It provides a web interface for your code and adds powerful features for collaboration, like Pull Requests and issue tracking.
Analogy: Git is like Microsoft Word—the software you use to write a document on your computer. GitHub is like Google Drive—the online service where you can store that document, share it, and collaborate on it with others.
The Core Workflow: Push and Pull
The basic idea of working with a remote repository like GitHub is simple. You work and make commits locally on your computer using Git. When you're ready to back up your changes or share them with your team, you push your commits to the remote repository on GitHub. If a teammate has pushed their own changes, you pull those changes down to your local computer to stay in sync.
Your Mission: Putting Your Project on GitHub
Let's take our local mvc-project
and push it to a new repository on GitHub.
Step 1: Create a GitHub Account
If you don't already have one, go to GitHub.com and sign up for a free account.
Step 2: Create a New Repository on GitHub
Once you are logged in, click the "+" icon in the top-right corner and select "New repository".
- Repository name:
mvc-project
(or any name you like) - Description: A simple PHP MVC framework built from scratch.
- Choose Public (so others can see your work) or Private.
- IMPORTANT: Do not initialize the repository with a README, .gitignore, or license file. We already have an existing project locally, and we want to push that up to an empty remote repository.
- Click "Create repository".
Step 3: Connect Your Local Repo to the Remote Repo
After creating the repository, GitHub will show you a page with several commands. We are interested in the section titled "...or push an existing repository from the command line".
Open your terminal in your mvc-project
directory and run these three commands exactly as GitHub provides them. They will look like this:
1. Add the remote origin: This command tells your local Git repository where its "home" on the internet is. origin
is the standard nickname for your primary remote repository.
git remote add origin https://github.com/YourUsername/mvc-project.git
(Replace the URL with the one you see on your GitHub page!)
2. Rename your main branch (optional but recommended): The default branch name in Git used to be "master", but the new standard is "main". This command ensures your branch is named `main`.
git branch -M main
3. Push your code: This is the command that actually uploads your local commits to GitHub.
git push -u origin main
push
: The command to upload.origin
: The nickname of the remote location we want to push to.main
: The name of the local branch we want to push.-u
: A one-time flag that links your local `main` branch with the remote `main` branch. In the future, you can simply rungit push
.
Step 4: Verify on GitHub
Refresh your GitHub repository page. All of your project files and your entire commit history should now be visible online!
Module Complete!
Congratulations! You now know how to use the two most essential tools for any modern developer: Composer and Git/GitHub. Having your code on GitHub not only backs it up but also serves as a portfolio you can show to potential employers. You've completed a major step in your journey to becoming a professional PHP developer.