How to Use Git: The Ultimate Beginner's Guide to Version Control


If you're new to Git or need a quick refresher, this guide walks you through the most commonly used Git commands to manage your code efficiently. Whether you're working solo or on a team, Git is the backbone of modern software collaboration.
🔧 Setting Up Git
Before you start using Git, set your name and email. These will appear in your commits.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
Use --global
to apply these settings across all repositories. Omit it to configure only the current repo.
📁 Starting a Project
Create a new repository:
git init
Clone an existing repository:
git clone https://github.com/username/repo.git
📄 Working with Files
Check status:
git status
- Stage a file: git add filename
- Stage all changes: git add .
- Commit your changes: git commit -m "A meaningful commit message"
🔄 Pushing & Pulling Code
- Push your branch to the remote repo: git push origin branch-name
- Pull the latest code from the remote repo: git pull origin branch-name
🌿 Branch Management
- Create a new branch: git branch new-branch
- Switch to a branch: git checkout new-branch
- Create and switch in one command: git checkout -b new-branch
🔁 Merging & Rebasing
- Merge another branch into the current one: git merge branch-name
- Rebase your branch onto another: git rebase main
⚠️ Use rebasing carefully in team environments to avoid overwriting shared history.
🧹 Clean Up and Restore
- Temporarily store changes: git stash
- Apply stashed changes back: git stash pop
- Discard all changes and reset: git reset --hard
📜 View History and Differences
- See commit history: git log
- Check unstaged changes: git diff
- Check staged changes: git diff --staged
🔚 Final Thoughts
Git is a powerful tool, but you don’t need to memorize every command. Start small, practice often, and use this cheat sheet as your guide. As your projects grow, so will your Git skills.
Subscribe to my newsletter
Read articles from Mohi uddin directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
