EP02: Getting Started with Git – Your First Step with git init



This content originally appeared on DEV Community and was authored by Booranasak Kanthong

Welcome back to our beginner-friendly Git series!

What Is git init?

Think of git init as setting up a “save system” for your project—like turning on version tracking. When you run this command inside a folder, Git starts watching it and keeps track of every change you make from now on.

It creates a repository, often called a “repo”—a space where Git stores all the version history of your files.

You’ll be able to save snapshots of your work, go back in time, and even collaborate with others. But before we get to the cool stuff, we need to set up Git in a project folder.

Step-by-Step: Using git init

Let’s create your very first Git repository.

1. Create a New Project Folder

Open your terminal or command prompt and type:

mkdir my-first-git-project
cd my-first-git-project

This will create a new folder and move you into it.

2. Initialize Git

Now, let’s tell Git to start tracking this folder:

git init

Done! You’ve now created a Git repository inside that folder.

If you want to check whether it worked, try:

#for Linux
ls -a 

#for Command Prompt
dir /a 

#for PowerShell
ls -Force

You should see a hidden .git folder. That means Git is now watching your project.

What’s in the .git Folder?

The .git folder is the brain of your project. It stores:

  • Your commits (project history)
  • Branches
  • Configuration
  • Remote tracking (later on)

You normally don’t touch it directly, but it’s the engine that powers Git.

Checking Git Status.

After running git init, try this:

git status

You’ll see a message like:

Let’s Add a File and Make Your First Commit

Before we add files and commit, let’s follow a best practice and create a develop branch instead of working directly on the default branch (master or main).

In professional workflows, the main branch is usually used for production-ready code, while develop is where active development happens.

1. Create and Switch to a New Branch

git checkout -b develop

This command does two things:

  • checkout -b develop: Creates a new branch called develop
  • Switches you to it immediately

2. Create a File

echo "# My Project" > README.md

You can run this command in the Linux CLI, Command Prompt, and PowerShell.

3. Check Git Status (Before Adding the File)

git status

You will see something like:

Git shows the new file (README.md) in red, meaning it has detected the file but isn’t tracking it yet.

4. Add the File

git add <filename>

In our case:

git add README.md

Once the file is added using git add, Git starts tracking it. In git status, the file name will now appear in green text, indicating that it is staged and ready to be committed.

6. Make Your First Commit (Conventional Style)

git commit -m "feat: initial commit with README"

Explanation:

  • feat: indicates that this is a new feature or starting point.
  • initial commit with README: short, clear description of the change.

If you want to specify a scope, for example core, it could look like this:

git commit -m "feat(core): initial commit with README"

You’ve now made your first properly formatted commit — great practice for working on any serious project or team.

Bonus: Push Your Code to GitHub

Now let’s learn how to push it to GitHub, so your code is backed up online and ready to collaborate with others.

Git tracks changes on your local machine, but you need to push them to GitHub to share or store your work remotely.

1. Create a Repository on GitHub

Head over to github.com and create a new repository.
Name it something like:

git-basics

Or choose a different name such as:

my-first-git-project

Important: Do not initialize the repo with a README, .gitignore, or license — you’ve already done that locally.

GitHub Repository Setup Screen
When creating your new repository, you’ll see the following options:

  • Choose a Repository name.
  • Add your Project Description (optional) — briefly explain what your project does or aims to achieve
  • Leave “Add a README file”, .gitignore, and License unchecked.
  • You can select either Public or Private visibility depending on your needs.
  • Then click Create repository.

This creates an empty repository that’s ready to receive code from your local machine.

2. After Creating the Repository

Once your repository is created, click into it. You’ll see a page like this:

“Add a README” section will still appear, but don’t worry — this simply means no README file exists in the remote repo yet. You’ll be pushing your local files (including README.md) soon.

3. Connect Your Local Repo to GitHub

To connect your local project to the GitHub repository you just created:

3.1) Click the green Code button near the top right.
3.2) In the dropdown that appears, choose either:

  • HTTPS – if you prefer using your GitHub username and password or token.
  • SSH – if you’ve already set up SSH keys (more secure and convenient in the long run).

3.3) Click the clipboard icon next to the URL to copy it.

Now, in your terminal, run:

git remote add origin <remote-url>

Replace the <remote-url> with the one you copied from GitHub. For example:

git remote add origin https://github.com/Mirrorsan/git-basics.git

This command tells Git: “Here’s the place I want to send my code online.”

You can verify the connection using:

git remote -v

It will show something like:

4. Push the develop Branch to GitHub

Time to send your work to GitHub! Run:

git push -u origin develop

What this does:

  • push: uploads your code to GitHub
  • -u: links your local develop branch to the remote develop branch
  • origin: the name of the remote (GitHub)
  • develop: the name of the branch you’re pushing

You will see some thing like:

What Happens Next?

Once you’ve pushed your code to GitHub, head back to your repository page and refresh the browser. You’ll now see your project files (like the README.md) and the full commit history that you just published from your local machine.

In the example below, you can see the branch named develop was pushed a few minutes ago. GitHub clearly shows that it now contains your initial commit, including the README file content you wrote locally.

Switching Between Branches

You’ll also notice a branch switcher at the top-left of the file viewer. If you’ve created multiple branches (like main and develop), you can switch between them using this dropdown.

This is especially helpful for working on features, reviewing past changes, or preparing for a pull request.

What You’ll See

  • The README.md content is now rendered beautifully right on the homepage of your repository.
  • The commit log reflects your project history (who did what, and when).
  • The branch selector helps you manage and navigate different lines of development.

You’ve officially published your first Git project to the world!

Whether you’re working solo or collaborating with a team, your project is now live, backed by version control, and ready for the next step — sharing, improving, or even open-sourcing.


This content originally appeared on DEV Community and was authored by Booranasak Kanthong