Start Git in a JS Project
So you've installed Git. Nice. Now let’s make it do something useful—like track changes in an actual JavaScript project. In this lesson, we’re going from zero to “Git is working in my app” in a few quick steps. We’ll set up a fresh JS project, initialize Git, make your first commit, and keep your repo clean with a .gitignore
file.
Trust me, the first time I used Git, I skipped .gitignore
, committed my node_modules
, and uploaded 300MB of garbage to GitHub. Learn from my rookie mistake.
Creating a New JavaScript Project
Start simple. Make a new folder anywhere you like:
mkdir my-js-project
cd my-js-project
Now drop in a tiny JavaScript file so Git has something to track:
echo "console.log('Hello Git');" > index.js
Want to make it a real JS project? Run:
npm init -y
Boom—now you’ve got a package.json
, which will be handy later when you start adding dependencies or scripts.
Initializing Git Repository
Time to invite Git to the party. In your project folder, run:
git init
This creates a hidden .git
folder where Git keeps its brain—every commit, every log, every branch. If you don’t see it, you’re not going crazy; it’s just hidden. But it’s there, quietly watching everything you do (kinda like your browser history 👀).
Want to see what Git thinks of your current project state?
git status
Get used to that command. You’ll be using it a lot.
First Commit and .gitignore
Right now, Git is tracking nothing. It's just lurking. So let’s stage our files and make our very first commit.
git add .
git commit -m "Initial commit"
🎉 You just created a version-controlled project. That might seem small now, but it’s a huge milestone in your dev journey.
Now, let’s talk .gitignore
. This file is like the “do not call” list for Git. It tells Git what to ignore—stuff like node_modules/
, .env
, .DS_Store
, or logs. It keeps your repo clean and your commits relevant.
Start with this:
echo "node_modules/" > .gitignore
Later, you can expand it. GitHub has a solid `.gitignore` template for Node.js if you want to go pro.
Fun fact: once I accidentally committed my .env
file with API keys in it. Big oof. Don’t be like me. Use .gitignore
.
What’s Next?
That’s it—you’ve got Git up and running in a JavaScript project. You can track changes, go back in time, and collaborate like a pro.
In the next chapter, we’ll go deeper and show you how to work locally with Git like a real developer. We’ll start with the Git workflow—add, commit, repeat—and explain how real-world teams keep their projects tidy. Even if you're flying solo, it's still worth learning this stuff right.
This is where Git starts to feel useful. Let’s go.