1. The problem without version control: why just copying files is a bad idea
Let's start with a real-life scenario. Imagine you're working on your C# project. Everything goes fine until the "experiments" moment arrives. You decide to change something but you're afraid to break the working version. What to do? Of course, copy the project!
As a result, masterpieces like this appear on your disk:
MyProject/
├── Main.cs
├── Main_backup.cs
├── Main_final.cs
├── Main_final2.cs
├── Main_tochno_final.cs
├── Main_tochno_tochno_final.cs
Sound familiar? Now imagine a friend joins the project. He also likes copying files — just in his own way. How do you know which is the freshest working version? How do you find out who changed what? How do you revert everything if the experiment failed?
Without version control:
- It's easy to lose or mix up working code.
- You can't "roll back" to an old version.
- It's hard to work with two or three people.
- Chaos and fear of experimenting.
These are exactly the problems that version control systems solve — such as Git.
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 lets developers save different versions of files and coordinate work of multiple people on a shared project.
Main Git concepts:
Repository
A repository (or "repo") is the place where the whole project history is stored, including all changes and versions of files.
Commits
commit is a saved state of the project. Each commit in Git contains information about what changes were made to the project, by whom and when. Commits form the project's history and let you go back 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 sequential history of changes.
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, 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"
The develop branch "forks" off the main main branch for parallel development. After finishing work, changes from develop are merged back into main.
3. Basic Git commands (what happens under the hood)
Below is the list of basic commands for working with Git via the terminal. It's important to understand which commands are at the core of all operations. However we'll stick to a GUI approach and learn to do all these actions using the convenient GUI of IntelliJ IDEA. Think of these commands as what happens "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. |
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 basic tools for working with Git, allowing you to manage code changes, branches, and merges in projects of any size.
sequenceDiagram
participant Rabochaya direktoriya
participant Oblast indeksatsii (Staging)
participant Lokalnyy repository
participant Udalennyy repository
Rabochaya direktoriya ->> Oblast indeksatsii (Staging): git add (Podgotovit)
Oblast indeksatsii (Staging) ->> Lokalnyy repository: git commit (Sokhranit lokalno)
Lokalnyy repository ->> Udalennyy repository: git push (Otpravit na server)
Udalennyy repository ->> Rabochaya direktoriya: git pull (Skachat obnovleniya)
4. Three places where code is stored
When you use a version control system for your code, it, roughly speaking, will be stored in three places:
1. Remote repository
This is the centralized place for storing your code, usually hosted on services like GitHub, GitLab, or Bitbucket. They provide centralized code storage and are the basis for collaboration. The remote repository serves as an integration point for automation processes like build, test, and deploy.
2. Local repository
The local repository is your personal copy of the code stored on your computer. In this repository you can perform all Git operations (commits, branching, merging) without needing an internet connection.
3. Working directory
The working directory on your computer contains the actual project files you're currently working on. It's the place where you can see and modify files, add new features, or fix bugs.
These components together provide a powerful infrastructure for source code management, allowing developers to manage project history and collaborate.
5. GitHub — your portfolio
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 lets users 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 you can show 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. Set parameters for the repository:
- 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. README is the "face" of your project.
- Add .gitignore: click the dropdown and choose a template for your language.
- Choose a license: you can skip this.
- Click
Create repository.
Step 4. Congratulations, your first remote repository is created!
7. Installing and configuring Git
Although you can learn Git basics through console commands (as shown in the video), in everyday work 99% of developers use the convenient tools built into the IDE. Our goal is to teach you to work like professionals.
The interface for working with Git in all modern JetBrains IDEs — whether IntelliJ IDEA for Java/Kotlin, Rider for C#, or PyCharm for Python — is practically identical. That means that once you learn to use Git in one environment you can easily apply those skills in any other. So we'll use IntelliJ IDEA as a universal example. Everything you see here will look and work the same in your favorite IDE.
To work with Git on your computer, Git needs to be installed first. If you use IntelliJ IDEA, it will most likely offer to install Git automatically if it isn't found on your system. We recommend accepting that — it's the easiest way.
Close the current project by choosing File > Close Project, and click Clone Repository.
If you prefer to install it manually, use the official site: https://git-scm.com/downloads.
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, switched to the more neutral term — main.
This is important to know because in some older articles or projects you may still encounter mentions of the master branch. In our lectures and in modern projects the main branch will always be main.
Learn more about the move to main at these links:
GO TO FULL VERSION