1. The problem without version control: why simply copying files is a bad idea
Let’s start with a real-life situation. Imagine you are working on your Kotlin project. Everything is going well—until the “experimentation” phase begins. You decide to change something, but you’re afraid of breaking the working version. What do you do? Of course: copy the project!
As a result, masterpieces like these appear on your disk:
MyProject/
├── Main.kt
├── Main_backup.kt
├── Main_final.kt
├── Main_final2.kt
├── Main_really_final.kt
├── Main_really_really_final.kt
Familiar? Now imagine that another friend joins the project. They also love copying files—just in their own way. How do you figure out which version is the newest and actually works? How do you find out who changed what? How do you roll everything back if the experiment fails?
Without version control:
- It’s easy to lose or mix up working code.
- It’s impossible to “roll back” to an older version.
- It’s hard to work with two or three people.
- Chaos and fear of experiments.
These are exactly the problems that version control systems solve—such as Git.
Video
Watch a lecture from one of the leading mentors at CodeGym University, who will immerse you in the world of Git—a key technology for any modern developer.
The video consists of two parts:
- First, you will go over the basics of working with Git via the terminal. This fundamental approach will help you understand what’s happening “under the hood” of the system.
- Then you will move on to practice in IntelliJ IDEA, where you will learn to perform the same operations using a convenient graphical interface, just like professionals do every day.
2. Why does a developer need Git?
Git is a powerful version control system used to track changes in source code during software development. It enables developers to save different versions of files and coordinate the work of multiple people on a shared project.
Core Git concepts:
Repository
A repository, or “repo,” is a place where the entire project history is stored, including all changes and file versions.
Commits
commit is a saved state of a project. Each commit in Git contains information about what changes were made to the project, by whom, and when. Commits form the project history and make it possible to return to any previous version.
gitGraph
commit id: "1"
commit id: "2"
commit id: "3"
commit id: "4"
commit id: "5"
commit id: "6"
Each commit is a “snapshot” of the project that follows the previous one, forming a consistent change history.
Branches
branch is an independent line of development. By default, Git creates the main branch. You can create new branches to develop new features or fixes and then merge them back into the main branch.
gitGraph
commit id: "1"
commit id: "2"
branch develop
commit id: "3"
commit id: "4"
commit id: "5"
checkout main
commit id: "6"
commit id: "7"
merge develop
commit id: "8"
commit id: "9"
A develop branch “branches off” from the main main branch for parallel development. After the work is finished, changes from develop are merged back into main.
3. Basic Git commands (what’s under the hood)
Below is a list of basic commands for working with Git via the terminal. It’s important to understand which commands are behind all operations. However, we will stick to a GUI approach and learn to perform all these actions using the convenient graphical interface in IntelliJ IDEA. Think of these commands as what’s happening “under the hood.”
| Command | Description |
|---|---|
git init |
Initializes a new Git repository in the current directory. |
git clone |
Clones a repository from a URL into a new directory. |
git add |
Adds files to the index for the next commit. |
git commit |
Records the staged changes in the repository. |
git push |
Sends changes from the local repository to the remote repository. |
git pull |
Updates the current branch with the latest version from the remote repository. |
git branch |
Shows, creates, or deletes branches. |
git merge |
Merges changes from the specified branch into the current branch. |
These commands are the core Git tools that let you manage code changes, branches, and merges in projects of any size.
sequenceDiagram
participant Working directory
participant Staging area (Staging)
participant Local repository
participant Remote repository
Working directory ->> Staging area (Staging): git add (Stage)
Staging area (Staging) ->> Local repository: git commit (Save locally)
Local repository ->> Remote repository: git push (Push to server)
Remote repository ->> Working directory: git pull (Download updates)
4. Four states (storage locations) of your code
When you use version control for your code, it will logically pass through four states:
1. Working directory (Working Directory)
The working directory on your computer contains the current project files you are working on at the moment. This is where you can see and modify files, write code, add new functionality, or fix bugs.
2. Staging area (Staging Area)
This is an intermediate zone between your working folder and the local repository. In IDE GUI terms, these are the very checkboxes you tick next to modified files before you click Commit. You choose which files and changes are ready to go into the next “snapshot” of history.
3. Local repository (Local Repository)
The local repository is your personal copy of the code history stored on your computer. In this repository, you can perform all Git operations (commits, branching, merging) without needing an internet connection.
4. Remote repository (Remote Repository)
This is a centralized place to store your code, usually hosted on services like GitHub, GitLab, or Bitbucket. They provide reliable code storage on servers and are the foundation for collaborative team work.
5. GitHub is your portfolio
It’s important to clearly separate two concepts: Git and GitHub. Git is a program that runs locally on your computer (even without the internet) and tracks file versions. GitHub, on the other hand, is a cloud service (website) where remote copies of your Git repositories are stored.
GitHub is the leading web platform for hosting source code, using the Git version control system. Founded in 2008, it quickly became one of the key tools for developers worldwide.
GitHub enables users to create repositories to manage projects, control and track code changes, and collaborate with other developers. For a modern developer, a GitHub profile is an important part of a portfolio that can be shown to potential employers.
6. Creating your first repository on GitHub
Step 1. Go to https://github.com and sign up.
Step 2. Click the New repository button to create a new repository.
Step 3. Configure the repository settings:
- Repository name: come up with a meaningful name.
- Public or private: for learning projects, it’s better to choose “Public” so others can see it.
- Add a README file: make sure to check this box. A README is the “face” of your project.
- Add .gitignore: click the dropdown and choose the Kotlin (or Java) template. This will protect your repository from large build artifacts and local IDE settings.
- Choose a license: you can skip this.
- Click
Create repository.
Step 4. Congratulations—your first remote repository has been created!
7. Installing and setting up Git
Although you can learn Git basics through console commands (as shown in the video), in day-to-day work 99% of developers use convenient tools built into the IDE. Our goal is to teach you to work the way professionals do.
The Git interface in all modern JetBrains IDEs—whether it’s IntelliJ IDEA for Kotlin/Java, Rider for C#, or PyCharm for Python—is almost identical. This means that once you learn Git in one environment, you’ll be able to apply those skills in any other. That’s why we’ll use IntelliJ IDEA as a universal example. Everything you see here will look and work exactly the same in your favorite IDE.
To work with Git on your computer, you first need to install it. If you use IntelliJ IDEA, it will most likely offer to install Git automatically if it’s not found on your system. We recommend accepting this suggestion—it’s the easiest path.
Close the current project by choosing File | Close Project in the top menu. On the start screen (Welcome Screen), click Clone Repository (in some interface versions it may be called Get from VCS).
If you want to install it manually, use the official website: https://git-scm.com/downloads.
An important nuance
When you make your first commit in the IDE, IntelliJ IDEA will ask you to identify yourself—enter your username and email. It is extremely important to enter the exact email you used to register your GitHub account.
The reason is that GitHub links the authorship of your commits to your profile using this email address. If the addresses match, your avatar will appear next to your commits, and the beloved “green squares” of activity on your profile page—the ones employers like to evaluate—will start to fill in.
8. A bit of history: main vs master
Previously, the default branch in Git was called master. However, in 2020 the developer community and major platforms, including GitHub, moved to using the more neutral term main.
This is important to know, because in some older articles or projects you may still encounter references to the master branch. In our lectures and in modern projects, the primary branch will always be main.
You can learn more about the transition to main using the following links:
GO TO FULL VERSION