{}const=>[]async()letfn</>var
Development

Git for beginners: first commands

Learn the basics of Git from scratch! In this article, you will find a step-by-step guide to the first commands of the version control system: from installation and configuration to creating commits and working with remote repositories.

К

Kodik

Author

6 min read

What is Git and why do you need it

Imagine that you are writing code and suddenly realize that the previous version worked better. Or you are working with a team, and you need to combine the changes of several people. Git solves these problems by keeping a history of all changes and allowing you to safely experiment with the code.

Git stores snapshots of your project in a special repository. Each save of changes is called a commit, and you can always go back to any of them.

🔥 100,000+ students already with us

Tired of reading theory?
Time to code!

Kodik — an app where you learn to code through practice. AI mentor, interactive lessons, real projects.

🤖 AI 24/7
🎓 Certificates
💰 Free
🚀 Start learning
Joined today

Git Installation

Before you start, you need to install Git on your computer. Download it from the official website git-scm.com and follow the installer instructions. After installation, open the terminal (command line on Windows or Terminal on Mac/Linux) and check the version with the command:

git --version

If the installation is successful, you will see the Git version number.

Git Setup

The first thing you need to do is introduce yourself to Git, indicating your name and email. This information will be attached to each of your commits:

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

The --global flag means that these settings will be applied to all your projects. You can check the current settings with the command:

git config --list

Creating the first repository

Now let's create our first repository. Go to your project folder and run the command:

git init

This command creates a hidden folder .git, in which Git will store the entire history of changes. Your project is now under version control, but there is nothing in the repository yet.

Status check

The git status command shows the current state of the repository. It displays which files have been modified, which are ready to be committed, and which are not tracked at all:

git status

You will use this command very often. It helps you understand what's going on in your repository right now.

Adding files

Create a file, for example index.html, and add some code to it. Git is not yet tracking this file. To add a file to the tracked files, use the command:

git add index.html

If you want to add all the modified files at once, use a dot:

git add .

After executing git add, the files are moved to the staging area, from where they will be included in the next commit. This is convenient when you want to save only part of the changes.

Creating a commit

A commit is a snapshot of the state of your project at a certain point in time. Each commit must contain a clear description of what has changed:

git commit -m "Added index.html file with basic structure"

The -m flag allows you to add a commit message directly in the command. Try to write meaningful messages that explain what you have changed and why. This is very helpful when you or your colleagues are reviewing the project history.

View history

The git log command shows the history of all commits in your repository:

git log

You will see a list of commits with their hashes (unique identifiers), authors, dates, and messages. For a more compact output, use:

git log --oneline

This command will show abbreviated hashes and commit messages in one line each.

View changes

If you have changed the files but have not yet added them to the staging area, the git diff command will show what exactly has changed:

git diff

This is useful when you want to check your edits before committing. To see changes in files that are already in the staging area, use:

git diff --staged

Cancel changes

Sometimes you need to undo changes. If you have modified a file but have not yet added it to the staging area, you can revert it to the last committed version:

git checkout -- index.html

If the file is already in the staging area, first remove it from there:

git reset index.html

Then, if necessary, roll back the changes with the checkout command.

Working with a remote repository

Often, the code is stored not only on your computer, but also on a remote server, for example, on GitHub or GitLab. To link a local repository to a remote one, use:

git remote add origin https://github.com/username/repository.git

Here origin is the standard name for the main remote repository. To send your commits to the server, run:

git push -u origin main

The -u flag establishes a connection between the local and remote branch. In the future, you can simply use git push.

To get changes from a remote repository, use:

git pull

This command downloads the changes and immediately merges them with your local code.

Cloning a repository

If the project already exists on a remote server, you can copy it to your computer:

git clone https://github.com/username/repository.git

This command will create a folder with the repository name and download all the code along with the commit history.

Basic workflow

A typical Git workflow looks like this:

  1. Make changes to project files

  2. Check the status with the git status command

  3. Add changes to the staging area with the git add command

  4. Create a commit with a description of the changes using the git commit command

  5. Send changes to the server with the git push command

Before you start, it's a good idea to update the code with the git pull command to get the latest changes from the team.

Useful tips

Always check the status of the repository before committing. This helps to avoid accidentally adding unnecessary files. Write clear commit messages, use verbs in the imperative mood, for example "Add", "Fix", "Update". Commit logically related changes together — do not put edits from different parts of the project into one commit.

Don't be afraid to experiment. Git always allows you to return to the previous state, so you will not break the project irrevocably. Regularly send code to a remote server — this will protect you from data loss in the event of a computer failure.

Conclusion

We have analyzed the basic Git commands, which are enough to start working with the version control system. As your experience grows, you will become familiar with branches, merges, conflict resolution, and other advanced Git features. But even these basic commands are enough to effectively manage the versions of your code and participate in team projects.

Practice, create repositories for training projects and don't be afraid to make mistakes. The ability to work with Git is a skill that will remain with you throughout your career as a developer and will open the door to participation in open source projects and team development.

Join the educational platform Code, where you will find structured courses in Python, JavaScript, HTML, CSS and other technologies for beginner developers.

Subscribe to our Telegram channelto receive useful articles, programming tips and keep up to date with new materials. Together we will make your path to development simple and clear!

🎯Stop procrastinating

Liked the article?
Time to practice!

In Kodik, you don't just read — you write code immediately. Theory + practice = real skills.

Instant practice
🧠AI explains code
🏆Certificate

No registration • No card