Version Control with Git
Imagine writing a long essay and every time you make a change, you save over the old version. Eventually, you mess something up… and there’s no “undo.” That’s what coding without version control feels like. In this chapter, we’ll cover the basics of Git, the most widely used version control system, so you can confidently track your code, collaborate, and avoid disasters.
What is Version Control?
Version control systems help you:
- x>Track changes to your code over time
- x>Revert to earlier versions when something breaks
- x>Collaborate with others without overwriting each other’s work
Git is the tool. GitHub is one of the places where you can store Git projects online.
Git in a Nutshell
Git works like a timeline of snapshots:
- x>You initialize a project as a Git repository
- x>You make changes → Git tracks them
- x>You commit changes with a message
- x>Git remembers every version

You now have a time machine.
Branching Out
Branches let you work on features independently:

- x>Your work doesn’t affect the main code.
- x>When done, merge it back:

This way, you can experiment freely and only merge when it works.
Using GitHub
You can push your code online to collaborate or back it up:

- x>Clone a repo: ''git clone https://github.com/someone/project.git''
- x>Create a branch and make changes
- x>Push changes
- x>Open a pull request (PR)
- x>Collaborate, review, and merge!
Best Practices
- x>Commit often with clear messages
- x>Use branches for features and fixes
- x>Keep your main branch clean and deployable
- x>Pull before you push to avoid conflicts
- x>Don’t commit sensitive info (passwords, tokens)
Git is a Lifesaver
Especially when working on teams or big projects, Git saves you from:
- x>Losing progress
- x>Breaking working code
- x>Accidentally erasing your teammate’s work
It’s more than just a tool — it’s a professional safety net.
What’s Next
Now that you know how to track and share your code, it’s time to ensure that it actually works. Up next, we’ll cover automated testing with JUnit and Mockito, so you can catch bugs before your users do. Let’s write code that’s not only versioned, but reliable.