What it is and why
A version control system keeps the history of changes to your project. Every commit is a snapshot you can return to.
Why a beginner needs it right now:
- Changing code stops being frightening. Broke it? Go back.
- Your work becomes visible. Commit history is something employers look at.
- Without it you can't work with people. At all.
How it works, simply
Three places your changes live:
- The working directory — the files you edit.
- The staging area — what you've marked for the next commit.
- The history — saved snapshots.
Edit a file and it's in the first. Stage it and it's in the second. Commit and it lands in the third.
Separately there's a remote repository: a copy of the history on a server that you push your changes to.
Ten everyday commands
Start tracking a project:
git init
See what changed:
git status
Stage files:
git add filename
git add .
Commit:
git commit -m "add amount validation to the expense form"
View history:
git log --oneline
Connect a remote:
git remote add origin address
Send changes:
git push
Fetch other people's changes:
git pull
Create a branch and switch to it:
git checkout -b branch-name
Discard changes to a file:
git checkout -- filename
Those ten carry you through the first months.
What not to track
Create an ignore file and add:
- folders with installed libraries;
- your virtual environment;
- files containing passwords and keys;
- editor and system junk;
- build output.
The third point matters most. A key that reaches the history is exposed forever: deleting it in the next commit leaves it in the history.
Common beginner mistakes
One commit for the whole project. A month's work in a single push — the history is useless.
Committing on a schedule rather than by meaning. Commit a finished piece of work, not "end of day".
Tracking everything. A two-hundred-megabyte repository in which code is one per cent.
Working only on the main branch. Tolerable alone. Not with people.
What to learn next
Branches and merging. The moment you understand why branches exist, working in a team stops being a mystery — and without team experience, interviews are hard.
Хватит читать — пора делать
На CohortX можно найти команду под пет-проект и получить тот самый опыт, о котором спрашивают на собеседовании.
Похожие статьи
- Working as a team: branches, merges and conflictsHow collaborative work on code is arranged, why branches exist, how to resolve conflicts and stay out of each other's way.
- Работа в команде: ветки, слияния и конфликтыКак устроена совместная работа над кодом, зачем нужны ветки, как разрешать конфликты и не мешать друг другу.
- Fixing mistakes in your history without breaking thingsWhat to do when you committed the wrong thing, forgot a file, wrote a bad message, or pushed a password.