
Version control is an essential skill for every developer, researcher, or data scientist. Git is the most widely used version control system, allowing you to track changes, collaborate safely, and manage project history efficiently.
This article walks through core Git concepts and commands, explaining what each does, how it is used, real examples, common beginner mistakes, and best practices.
1. What Is Git?
Git is a distributed version control system that records changes to files over time. Each developer has a full copy of the repository, including its entire history.
Why Git Matters
- Tracks changes in code and documents
- Enables collaboration without overwriting work
- Allows rollback to previous versions
- Supports branching and experimentation
2. Initializing a Repository (git init)
What It Does
Creates a new Git repository in your project directory.
Example
mkdir my_project
cd my_project
git init
This creates a hidden .git/ directory that stores all version control metadata.
Common Mistakes
- Initializing Git inside another Git repository
- Deleting the
.gitfolder accidentally
Best Practices
- Initialize Git once per project
- Run
ls -ato confirm.gitexists
3. Cloning an Existing Repository (git clone)
What It Does
Creates a local copy of a remote repository (e.g., from GitHub).
Example
git clone https://github.com/user/repo.git
When to Use
- Starting work on an existing project
- Contributing to open-source repositories
Common Mistakes
- Editing files before understanding the project structure
- Cloning into an unintended directory
Best Practices
- Read the
README.mdfirst - Clone repositories in a dedicated
projects/folder
4. Checking Repository Status (git status)
What It Does
Shows the current state of the working directory and staging area.
Example
git status
Output Tells You
- Modified files
- Staged files
- Untracked files
Common Mistakes
- Forgetting to run
git statusbefore committing
Best Practices
- Run
git statusfrequently - Treat it as your “sanity check” command
5. Tracking Files (git add)
What It Does
Moves changes from the working directory to the staging area.
Examples
git add file.txt
git add .
Common Mistakes
- Using
git add .blindly - Accidentally staging large or sensitive files
Best Practices
- Stage files intentionally
- Use:
git add file1.py file2.py
6. Committing Changes (git commit)
What It Does
Records a snapshot of staged changes in the repository history.
Example
git commit -m "Add initial data preprocessing script"
Common Mistakes
- Vague messages like
"update"or"fix" - Committing too many unrelated changes at once
Best Practices
- Write clear, descriptive commit messages
- Follow a pattern:
Short summary (50 chars max)
Optional detailed explanation
7. Viewing History (git log)
What It Does
Displays the commit history.
Example
git log --oneline
Use Case
- Understanding project evolution
- Debugging when a bug was introduced
Common Mistakes
- Ignoring commit history completely
Best Practices
- Use
--onelinefor readability - Learn to search logs later with
--grep
8. Ignoring Files (.gitignore)
What It Does
Prevents certain files from being tracked.
Example .gitignore
__pycache__/
*.log
.env
data/
Common Mistakes
- Adding
.gitignoreafter committing files - Forgetting to ignore large datasets
Best Practices
- Create
.gitignoreearly - Never commit secrets (API keys, passwords)
9. Branching (git branch, git checkout, git switch)
What It Does
Branches allow parallel development.
Example
git branch feature-x
git switch feature-x
Why Branches Matter
- Isolate experiments
- Avoid breaking the main codebase
Common Mistakes
- Doing all work on
main - Forgetting which branch you are on
Best Practices
- Keep
mainstable - Use descriptive branch names:
feature/login-ui
bugfix/memory-leak
10. Merging Branches (git merge)
What It Does
Combines changes from one branch into another.
Example
git switch main
git merge feature-x
Common Mistakes
- Merging without pulling latest changes
- Panic when conflicts appear
Best Practices
- Commit before merging
- Resolve conflicts line by line, not blindly
11. Working with Remote Repositories (git push, git pull)
Pushing Changes
git push origin main
Pulling Updates
git pull origin main
Common Mistakes
- Forgetting to pull before pushing
- Force pushing (
--force) without understanding consequences
Best Practices
- Pull frequently
- Avoid force push on shared branches
12. Common Beginner Git Mistakes (Summary)
- Forgetting to commit changes
- Writing poor commit messages
- Tracking unnecessary files
- Working directly on
main - Ignoring merge conflicts
13. Git Best Practices for Beginners
- Commit early and often
- Keep commits small and focused
- Use
.gitignore - Check
git statusregularly - Learn Git incrementally — don’t rush
Conclusion
Git is not just a tool — it is a workflow discipline. Mastering Git basics early will save you hours of debugging, collaboration issues, and lost work later.
Once you are comfortable with these fundamentals, you can explore:
- Rebase
- Stashing
- Tags
- GitHub workflows and pull requests
Coming Soon in Part 2…
Originally published on Medium.