So one day I was watching a YouTube video and there was this guy developing a web app. At the time I didn’t know much about development, so the first thing he did was type something into his terminal—and boom, lines started appearing and his whole codebase downloaded from somewhere on the internet. My jaw dropped. That was around three years ago. If you’ve had that moment too, stick with me: in this article I’ll cover what Git and GitHub are, how we use them to manage projects, and why they matter.

Originally published on Medium in FAUN.dev().

What’s Git and GitHub?

Git is version-control software. It’s used for tracking changes in a set of files—like the files in your codebase when you’re building an application—and is usually used so developers can coordinate work while building source code together.

Let me make that a bit simpler. Imagine you have four people on a team building a website. How do you work on the project at the same time? One option is to zip all the files, email the zip, then the next person makes changes, zips again, and sends it back. To avoid chaos, only one person can edit at a time—and even then it’s exhausting. Every small change means zipping everything and shipping it over email. That’s too much work for a developer.

That’s the need for Git and GitHub. Think of GitHub as an online folder where you keep your code. Anyone on the team can pull the code, make changes, commit them, and push back to that online folder. The next time you look, you can see who edited the code and what they changed or added.

Git and GitHub are tools that make development easier.

Sign up on GitHub

That’s the first thing to do. Visit github.com, click Sign up, then:

  1. Enter your email
  2. Set a password
  3. Set a username
  4. Solve a simple captcha puzzle
  5. Verify your email

That’s it. You’ll be redirected to your GitHub dashboard.

GitHub dashboard with a Create repository button in the left sidebar
A new GitHub account dashboard, ready to create the first repository.

As covered above, GitHub is where we store project code so we can access it from anywhere and share it with the world. We do that by creating repositories—think of them as folders that hold the files for each project.

If you have two projects, you create two repositories, and each project’s files live in its own repo.

Create a repo by clicking Create repository on the left. You’ll get a form that looks something like this:

GitHub Create a new repository form with name, description, and public or private options
The Create a new repository form on GitHub.
  1. Give your repo a name. It must be unique among your repositories—no two of yours can share a name.
  2. Leave the description blank if you want; it’s optional.
  3. Choose public (anyone can see and copy the code, but they can’t edit the repo without your permission) or private. Prefer public if you want to showcase the work.
  4. Don’t check any of the boxes below; we’ll handle those later.
  5. Hit Create repository.

A page like the one below will appear:

Empty GitHub repository quick setup page with HTTPS remote URL and command-line instructions
Quick setup page for a new empty repository, including the remote URL.

Leave this tab open—we’ll come back to it soon. First, download and install Git on your machine.

Installing Git

Search for “download Git,” open the first result, and download the installer for your operating system. Run the installer—keep clicking Next, then Install.

To check that Git installed correctly, run this in your terminal:

git --version

That prints the installed Git version.

Next, add your GitHub account details to the local Git config:

git config --global user.name "Your Name"
# e.g. git config --global user.name "Akshat Trivedi"

git config --global user.email "you@example.com"

Adding Git to a project

To initialize a project as a Git repository, run this from inside your project folder:

git init

It’s similar to running npm init to start a Node project.

After that, create a file named .gitignore. It lists files and folders you don’t want Git to track—for example .env files and the node_modules folder.

node_modules/
*.env

Put that in .gitignore for a Node project. With it in place, everything under node_modules is ignored, along with any file whose name ends in .env.

Staging and committing files

Diagram of Working directory, Staging area, and repository with git add and git commit arrows
How changes move from the working directory to the staging area, then into the repository.

Here’s the basic flow. After you edit project files, you add them to the staging area—and you do that for each file in the working directory once you’re ready.

git add app.js

That’s how you stage one file. Staging every file one by one gets tiring, so use this to stage all untracked changes at once (files that were edited and have changes Git doesn’t know about yet):

git add .

That adds every untracked file—or every file with untracked changes—to the staging area.

Once your edits are staged and you want Git to record them, commit with:

git commit -m "message you want to give to this commit"

Adding a remote repository

Remember the repository we created on GitHub? Now we add that remote to the local project and push our code.

git remote add [name_you_want_to_give_this_repo] [link_to_your_remote_repo]

You can name the remote whatever you like, but origin is the conventional name. Earlier I asked you to leave the new-repo tab open—go back to it now.

Empty GitHub repository page highlighting the HTTPS remote URL for github_demo
Copy the HTTPS URL from the empty repository page to use as your remote.

In that screenshot you’ll see a link—that’s the URL of your remote repository. Copy it into the command. It ends up looking like this:

git remote add origin https://github.com/akshat-triv/github_demo.git

That’s the setup. With your files already committed, push those commits to the remote with:

git push origin master

origin is the remote you’re pushing to, and master is your current branch. Don’t worry too much about branches yet—we can cover that in another article. (Newer GitHub repos often use main instead of master; if yours does, push to main.)

That’s it—congratulations on your first push. The ongoing loop is the same: write code, stage the files when a change is ready, commit, and push those commits to the remote when you’re done.

One more useful command:

git clone https://github.com/akshat-triv/github_demo.git

That’s how you clone a remote repository onto your machine—and that’s the command the developer in the YouTube video used at the start of this story.

Thanks for reading. There’s a lot here; if something’s unclear, dig into the official Git documentation or GitHub Docs while you practice the commands above.