DEV Community

nancy mueni
nancy mueni

Posted on

New to Git? Learn Version Control, Push & Pull Step by Step

Why Git Matters
Writing code without Git is like writing a document without a save history. Mistakes happen, files change, and ideas evolve. Git helps you keep track of every change you make, so you can confidently experiment, fix bugs, and improve your code without fear of losing work.
Git also makes collaboration simple. Whether you’re working alone or with a team, Git allows everyone to contribute safely by tracking changes and merging work smoothly. If something breaks, Git lets you roll back to a previous working version in seconds.
In short, Git gives developers peace of mind and structure as projects grow.

What is Version Control
Version control is a system that helps you track changes made to files over time. Instead of overwriting your work every time you make an update, version control saves each change as a new version. This allows you to view past versions, compare changes and restore earlier versions if needed.
In software development, version control is used to manage code as it grows and evolves. It keeps a record of what changed, who made the change, and when it happened.
Version control is important because it provides safety, organization, and collaboration.

  • It prevents loss of work by keeping a complete history of changes.
  • It allows you to experiment freely, knowing you can undo mistakes.
  • It makes teamwork easier by managing contributions from multiple people.
  • It helps maintain a stable and organized codebase as projects scale.

Without version control, managing code changes becomes messy and risky, especially when working in teams.

Basic Concepts
Repository (Repo)
A repository is a storage space for your project. It contains all your files, folders, and the complete history of changes made to them. A local repository is on the computer, whilst the remote repository is hosted online.

Working Directory
The working directory is where you write and edit your code. Any changes you make here are not tracked yet.

Staging Area (Index)
The staging area is a temporary holding area where you select changes you want to include in your next commit. By adding files to the staging area, you are telling Git,these are the changes I want to save. This gives you control over what gets committed.
git add filename

Commit
A commit is a snapshot of your project at a specific point in time. It records the changes you staged along with a message describing what was changed. Each commit has a unique ID, includes a message and becomes part of the project’s history. Commits allow you to move backward and forward through your project’s timeline.
git commit -m "Add login feature

Branch
A branch is a separate line of development. It allows you to work on new features or fixes without affecting the main codebase. The default branch is usually called main. Branches make it safe to experiment and collaborate.
git branch feature-login
git checkout feature-login

Remote Repository
A remote repository is a version of your project stored online. It allows you to share your code and collaborate with others eg GitHub, GitLab, and Bitbucket.
git remote add origin https://github.com/username/project.git

Push
Pushing means sending your local commits to a remote repository. This updates the shared project with your latest changes.
git push origin main

Pull
Pulling means fetching changes from a remote repository and merging them into your local project. This keeps your local code up to date.

git pull origin main

Key Note: Git is just saving versions of your work in a smart and organized way.

Top comments (0)