Git & GitHub for Beginners: From Zero to First Commit
Before we start Most people meet Git the hard way. Someone tells you to “just push it to GitHub,” you paste some commands you do not understand, something breaks, and you quietly decide Git is scary. It is not scary. It is one of the most useful tools you will ever learn, and the whole core of it fits in one sitting. This guide takes you from nothing to your first commit pushed to GitHub, with the reasoning behind each step so the commands stop feeling like magic spells. Follow along on a real folder as you read. By the end you will have done the thing, not just read about it. 1. What is Git? What is GitHub? Git is a version control system. That is a tool living on your own computer that keeps a complete history of every change you make to your files. Think of it as a time machine for your project. Made a mess? Roll back to a working version. Want to try something risky? Branch off safely and throw it away if it fails. GitHub is a website that stores your Git projects online. It backs up your work, lets you collaborate with other people, and lets you share projects with the world. The simplest way to hold the difference: Git is the engine that runs on your machine. GitHub is the garage where you park your work and show it off. You can use Git with no GitHub at all. Most people use both together. A bit of history. Git was created by Linus Torvalds in 2005, the same person who built the Linux kernel, because he needed to manage a project thousands of people were editing at once. GitHub came along in 2008 and was bought by Microsoft in 2018. 2. Installing Git and setting it up once Download Git from git-scm.com for Windows or macOS, or install it through your package manager on Linux. Once it is installed, open your terminal and tell Git who you are. This identity gets stamped on every commit you make, so do it once now. One thing that saves headaches later: use the same email address you sign up to GitHub with. That is what links your commits to your GitHub profile, so your work actually shows up as yours. 3. Your first repository A repository, or “repo,” is nothing more exotic than a folder that Git is watching. You either turn a folder you already have into a repo, or you copy an existing one down from GitHub. Running git init quietly creates a hidden .git folder inside your project. That folder is where Git keeps the entire history. You never need to open it or touch it by hand. Leave it alone and it does its job. 4. The three-stage workflow (this is the part that matters) If you understand one thing about Git, make it this. Every change you make travels through three places before it becomes a permanent part of your history. Almost every beginner who finds Git confusing is confused right here, usually about the middle stage. Here is the honest analogy that makes it click. Imagine packing a box to put in storage. The staging step is the one people skip past, but it is the useful one. It lets you make ten changes and save them as two clean, separate commits, instead of one messy lump. Here is the workflow in commands: Write commit messages as instructions, not diary entries. “Fix login bug,” not “Fixed login bug.” It reads oddly at first, but it is the convention, and future-you skimming the history will find it clearer. 5. Putting your work on GitHub Your commits so far live only on your computer. To back them up and share them, you push them to GitHub. First create a new, empty repository on github.com (the “+” icon, top right), then connect your local project to it. The confusion that catches everyone once: committing and pushing are two different things. A commit saves to your local history. A push sends those commits up to GitHub. You can commit ten times offline on a train, then push all ten at once when you get wifi. If your work is not showing up on GitHub, you almost certainly committed but forgot to push. The -u flag on that first push sets origin main as your default, so from then on a plain git push is enough. 6. Branches: how you work without fear A branch is a separate line of work. You make one whenever you want to build a feature or fix a bug without risking the version that currently works. When the work is good, you merge it back into the main line. Once a branch is on GitHub, you can open a pull request, usually called a PR. A pull request is a tidy way to say “here are my changes, please review them before they go into main.” Your teammates can comment, suggest fixes, and approve. This is the everyday workflow in basically every real project, open-source or professional. A rule worth adopting early: on a team project, never commit straight to main. Always branch, then open a PR for review. And if a command ever behaves strangely, run git status and git branch first. Nine times out of ten you are simply on a different branch than you thought. 7. The commands you will actually use You do not need all of Git to be productive. This small set covers almost everything day to day. The cheat sheet below is built to be saved and pinned somewhere you can see it while you find your feet. Command What it does git init Start tracking a project in this folder git clone <url> Copy a remote repo to your machine git status Show what has changed and what is staged git add . Stage all your changed files git commit -m “msg” Save a snapshot, with a message git push Upload your commits to GitHub git pull Download and merge changes from GitHub git log –oneline View a compact history git
Git & GitHub for Beginners: From Zero to First Commit Read Post »

