How to Use Git for Version Control: A Step-by-Step Guide

Git is an essential tool for tracking code changes, collaborating with teams, and maintaining a clean project history. This tutorial covers the core commands every beginner needs to start using Git effectively.

First, install Git from git-scm.com and configure your name and email with git config --global user.name "Your Name" and git config --global user.email "your@email.com". Then navigate to your project folder and run git init to initialize a new repository.

Article illustration

1. Staging and Committing Changes

After modifying files, stage them with git add filename or git add . to stage everything. Then create a snapshot using git commit -m "Your commit message". Each commit saves a point you can return to.

2. Branching for Parallel Work

Branches let you work on features without affecting the main code. Create a new branch with git branch feature-name, switch to it using git checkout feature-name (or git switch feature-name). Merge changes back with git checkout main then git merge feature-name.

3. Using Remote Repositories

Remote services like GitHub store your code online. Clone an existing repo with git clone repo-url. Add a remote with git remote add origin url. Push your commits using git push origin main, and pull updates from others with git pull origin main.

Mastering these Git fundamentals will make your development workflow smoother and safer. Start by practicing on a small project, and soon you’ll be handling version control with confidence.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *