Skip to content
TechCareer Lab

Git Basics: Create Your First Repository

Set up Git, create a repository, make commits, and work with branches. The core commands every developer uses daily, explained step by step.

Author
TechCareer Lab Team
Published
Reading time
3 min read
On this page

Git is a version control system: it records changes to your files over time so you can review history, undo mistakes and work on features in parallel. Almost every software team uses it, so it is one of the first tools worth learning properly.

This tutorial covers the commands you will use every day.

Install and configure Git

Check whether Git is installed:

git --version

If it is not, download it from the official site at git-scm.com. Then tell Git who you are. This name and email are recorded in every commit you make:

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

Optionally, make main the default branch name for new repositories:

git config --global init.defaultBranch main

Create a repository

A repository is a folder whose history Git tracks. Create a project folder and initialise it:

mkdir my-first-repo
cd my-first-repo
git init

Git creates a hidden .git folder that stores the history. Don't edit it by hand.

The basic workflow: status, add, commit

Create a file, then ask Git what has changed:

echo "# My First Repo" > README.md
git status

Git reports README.md as untracked. Saving a change takes two steps:

  1. Stage the changes you want to include with git add.
  2. Commit them with a message describing what changed.
git add README.md
git commit -m "Add README"

The staging step lets you choose exactly which changes go into each commit, which keeps history clear.

View history

git log --oneline

Each line shows a short commit ID and its message, newest first.

Work on a branch

Branches let you develop a feature without affecting the main line of work. Create a branch and switch to it:

git switch -c add-about-section

Make and commit your changes on this branch:

echo "This project is for learning Git." >> README.md
git add README.md
git commit -m "Add project description"

When the work is ready, switch back to main and merge the branch:

git switch main
git merge add-about-section

git switch was added in Git 2.23. On older versions, use git checkout -b <name> to create a branch and git checkout <name> to switch.

Ignore files you don't want to track

Some files should never be committed, such as dependencies, build output and files containing secrets. List them in a .gitignore file in the repository root:

node_modules/
.env
*.log

Next steps

You now know the core local workflow: init, status, add, commit, log, switch and merge. The natural next step is connecting your repository to a hosting service such as GitHub with git remote and git push, so you can back up your work and collaborate.