If you’re like me, you probably heard people talking about "pushing to main" or "merging branches" and thought, “What on earth are they talking about?”
It feels like everyone knows this secret language. But honestly? Once you get the hang of it, Git and GitHub are just a fancy way of making sure you don't accidentally delete your entire project.😊
Let’s break it down.
This guide will walk you through the fundamentals of Git and GitHub. You'll learn how to install them, connect them, and use them to manage your code effectively.
What is Git?
Git is a version control system. Think of it as a smart history book for your code. Every time you make changes to your project, Git can record them. This means you can:
- Track modifications: See exactly what changes were made, when, and by whom.
- Revert: Easily go back to an earlier state of your code if something goes wrong.
What is GitHub?
GitHub is a web-based hosting service for Git repositories, like the cloud (think Google Drive).
While Git is the tool you use on your computer to manage versions, GitHub is like a cloud storage and collaboration platform for your Git projects. It allows you to:
- Store: Keep a backup if your laptop decides to take a permanent nap.
- Share: Make your projects accessible to others.
- Collaborate: Provide a central hub for others to work on a project with you without overwriting each other's work.
- Showcase: Create a portfolio of your projects.
Step 1: Installing Git Bash
Git Bash is a command-line interface (CLI) for Windows where you type commands to talk to Git.
For Windows:
- Download Git Bash: Go to the official Git website: https://git-scm.com/download/win
- Run the installer: Follow the on-screen instructions. You can generally stick with the default options, but here is something to keep in mind:
- "Choosing the default editor used by Git": You can keep the default (Vim) or choose another editor you're familiar with (like VS Code, Notepad++, etc.).
-
"Adjusting the name of the initial branch": Choose "Let Git decide" (it usually defaults to
mainnow).
- Verify the installation: Open the Git Bash application, type
git --versionand press Enter. You should see the Git version number.
Step 2: Configuring Git
Before you start using Git, you need to tell it who you are.
This information will be attached to your commits to track who is making changes.
While still on Git Bash and run these two commands, replacing the placeholders with your name and email:
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
You can verify your settings with:
git config --global --list
Step 3: Connecting the Two (The Handshake)
You will first need a GitHub account.
If you don't have one already, head over to https://github.com/join and sign up.
Follow the prompts to create your username, password, and verify your email.
Now, to make your computer talk to GitHub without asking for your password every five seconds, we use something called an SSH Key.
- Generate a new SSH key: In Git Bash, type:
ssh-keygen -t ed25519 -C "your@email.com"
Just keep hitting Enter until it stops.
- Start the SSH agent:
eval "$(ssh-agent -s)"
- Add your SSH key to the SSH agent:
ssh-add ~/.ssh/id_ed25519
- Copy your public SSH key:
cat ~/.ssh/id_ed25519.pub
A bunch of random letters and numbers will pop up. Highlight and copy them.
- Pass this to GitHub: Go to your GitHub settings, look for SSH and GPG keys, click New SSH Key, and paste that wall of text in there.
Step 4: Your First Project (The Fun Part)
Let’s say you have a folder on your computer called my-cool-app.
- Tell Git to watch this folder: Inside Git Bash, go to that folder and type
git init
-
Make a file: Create a simple text file called
readme.txtand write "Hello world" inside it. - The "Add and Commit":
git add .
git commit -m "My first save point"
(This tells Git, "Hey, look at all the changes I just made!").
Step 5: Sending it to the Cloud (Pushing)
Now, go to GitHub, create a "New Repository," and name it whatever you want. GitHub will give you a link that looks like git@github.com:yourname/your-repo.git.
- Link them up: Type,
git remote add origin [PASTE YOUR LINK HERE]
- Send it!:
git push -u origin main
Refresh your GitHub page, and boom! Your code is on the internet.
Step 6: Pulling it Back
If you ever go to a different computer, or if a friend changes your code on GitHub, you need to bring those changes back to your machine.
Just type:
git pull origin main
It’s like syncing your phone—it grabs the newest version from the cloud and puts it on your computer.
Wrapping Up
That’s pretty much the "Big Three":
- Add (Pick what you want to save)
- Commit (Save it)
- Push (Send it to GitHub)
Don't worry if you forget the commands at first. I still have to Google them half the time.
Just keep playing around with them, and eventually, it’ll feel like second nature.
Happy coding!🥳
Top comments (0)