DEV Community

jim kinyua
jim kinyua

Posted on

Git for Beginners: How to Push & Pull Code, Track Changes, and Understand Version Control

Git Basics for Beginners: Push, Pull, and Track Code Changes

Git is a version control tool that helps developers track changes in their code and collaborate safely. Instead of creating multiple versions of the same file, Git records what changed, when it changed, and who made the change. This makes it easy to work in teams and recover from mistakes.

Git works in a project folder called a repository. You work locally on your computer, then sync your changes to a remote repository such as GitHub.

Creating a Git Repository

Start tracking a new project:
git init

Copy an existing project:
git clone https://github.com/username/project.git

Tracking Changes

Check the current state of your project:
git status

Stage a specific file:
git add filename.js

Stage all changes:
git add .

Save a checkpoint:
git commit -m "Add login validation"

Pushing and Pulling Code

Send your commits to the remote repository:
git push

First-time push:
git push -u origin main

Get the latest updates from the remote repository:
git pull

Always pull before starting work to avoid conflicts.

A Typical Daily Git Workflow

git pull

write code

git status

git add .

git commit -m "Fix payment validation bug"

git push

Viewing History and Changes

View commit history:
git log

See what changed in files:
git diff

Common Beginner Mistakes

Forgetting to pull before working, writing unclear commit messages, committing broken code, or being afraid to make mistakes. Git is designed to recover from errors safely.

Final Thoughts

Git is simply about tracking changes, saving checkpoints, and syncing work with others. Learn these core commands first: git status, git add, git commit, git push, and git pull. Everything else builds on them.

Top comments (0)