Understanding Git Version Control: Track Changes, Commit, Push & Pull (Beginner Guide)
Source: Dev.to
What is the meaning of Version control, Push and Pull
Version control (Git)
Version control is a system that records changes to your files over time.
In simple terms, it’s like having a save history for your project. With Git, you create checkpoints called commits. Each commit becomes part of your project history, so you can see what changed, know when it changed, and go back to an earlier version if needed.
Useful Git commands
git status # Show changed files and their commit status
git add . # Stage all changed files for the next commit
git commit -m "..." # Create a commit with a message
git log # List all commits with author, date, and message
git show # Show the changes introduced by a specific commit
git restore # Revert a file to the last committed state
git checkout # View an older version without altering current work
git checkout main # Return to the latest version on the main branch
Push
Push means sending your saved commits from your local repository to a remote repository (e.g., GitHub). When you push:
- Your work is uploaded to GitHub.
- It is backed up online.
- It becomes available for sharing or collaboration.
If you don’t push, your work remains only on your computer.
Common push workflow
# First push of a new repository
git push -u origin main # Use "master" instead of "main" if your default branch is master
# Check which branch you are on
git branch # or git status
# Rename the current branch to main (if needed)
git branch -M main
# Subsequent pushes
git push
Note: Before pushing, changes must be committed with
git addandgit commit.
Pull
Pull means downloading the latest commits from a remote repository (e.g., GitHub) to your local repository.
This is important when:
- You work on multiple computers and need the same files everywhere.
- You collaborate with others and want their latest changes.
- Updates were made directly on GitHub and you need them locally.
Pull‑related commands
git pull # Download and integrate changes from the remote
git fetch # Check for updates without merging them
git merge # Combine fetched changes with your local files
git fetch only updates your local repository’s knowledge of remote commits; it does not modify your working files. Use it when you want to review changes before applying them.
Other useful options (covered later) include git pull --rebase, git restore, and git reset --hard.
A Practical Example: Tracking Changes and Pushing/Pulling from GitHub (Part 4)
Now that we understand version control, push, and pull, the next part of the series will walk through a simple, end‑to‑end example that demonstrates how these commands work together. Stay tuned for Part 4, where we’ll also explore additional Git commands.