Every professional programmer uses version control. It is not optional, nor a "plus" for the resume: it is the basic tool that allows you to work without fear of breaking code, collaborate in teams, and maintain a complete change history. Git is the system; GitHub is the most popular platform for hosting projects. If you are starting out, this tutorial takes you from zero to your first working repository.
What Problem Does Git Solve?
Imagine you are building a website. You make a change, it works, but the next day you try to add a new section and everything breaks. Without Git, your only option is to remember what you deleted or start from scratch. With Git, you return to the working version in a second, compare changes, and understand exactly what broke everything.
Installation and Initial Setup
- Download Git from git-scm.com and install it with the default options.
- Open the terminal (Git Bash on Windows, Terminal on Mac/Linux).
- Set your name and email:
git config --global user.name "Your Name" git config --global user.email "[email protected]"
The Commands You Will Use 90% of the Time
Start a Project
git init
This creates a Git repository in the current folder. From here, Git starts tracking changes.
Check Status
git status
It shows you which files changed, which are ready to save, and which Git does not yet know about.
Stage Changes
git add filename
Or, to add everything at once:
git add .
Save a Version
git commit -m "Clear description of the change"
Each commit is a snapshot of the project at a specific moment. Write descriptive messages; your future self will thank you.
View History
git log --oneline
Lists all your commits in compact form.
Connecting to GitHub
GitHub is a cloud service where you can upload your repository, share it, and collaborate.
- Create an account at github.com.
- Generate a personal access token (Settings > Developer settings > Personal access tokens).
- Create a new repository on GitHub.
- On your computer, link it:
git remote add origin https://github.com/youruser/yourrepo.git git branch -M main git push -u origin main
From now on, every time you run git push, your changes are uploaded to GitHub.
Recommended Daily Workflow
- Before starting work:
git pullto bring in changes from the team. - Work on your code normally.
- When you finish a feature:
git add .,git commit -m "message",git push. - If something breaks:
git log --onelineto see recent commits, andgit checkout <commit-id>to go back.
Key Concepts You Must Understand Well
- Repository: the folder that Git watches.
- Commit: a saved snapshot of the project.
- Branch: an independent line of development. The main one is called
mainormaster. - Merge: combining two branches into one.
- Push/pull: uploading changes to GitHub / bringing changes from GitHub.
Typical Mistakes and How to Avoid Them
- Forgetting to commit for hours: if the power goes out, you lose everything. Commit every time you finish a small feature.
- Meaningless commit messages: "asdf" or "changes" help no one. Describe what you did and why.
- Pushing directly to
mainon a team: learn to create branches for each task before collaborating with others.
At Crezendo, we include Git and GitHub from day one of our web development courses. You learn to work as a professional team does, with shared projects and real code reviews. If you need a computer to practice, we can help you get donated equipment in good condition. Write to us and start versioning your future.