Git Without the Tutorial Hell: What Solo Developers Actually Need
Hello there. If you’re starting to code, you’ll inevitably encounter “Git” and “GitHub.” Rather than giving you textbook definitions, this article focuses on what you actually need to know to work effectively — practical techniques you can use starting tomorrow.
Two Things to Understand First
Git and GitHub are different things. Git is a version control tool that runs on your computer and records the history of your file changes. Developed by Linus Torvalds in 2005, it’s now the standard tool for development. GitHub, on the other hand, is a service for sharing projects managed with Git on the internet. Think of Git as the tool and GitHub as the warehouse.
The second important thing: Git is fundamentally a “save point system.” Like saving in a video game, you can record the state of your work at any moment and return to any previous state whenever needed.
Day One: Environment Setup
Before you start using Git, there’s a one-time configuration:
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
This information gets recorded in every commit and is used to track who made what changes.
Real Development Workflow: A Day’s Work
In actual development, you’ll follow this flow:
1. Starting a Project
For a new folder:
cd project-folder
git init
Joining an existing project:
git clone https://github.com/username/repository-name.git
Clone copies the entire project from GitHub to your computer.
2. Create a Working Branch
Don’t work directly on the main branch. Create a feature branch for each task:
git checkout -b feature/feature-name
For example, if you’re building a login feature, name it something like “feature/login.”
3. Write Code and Save
After editing files, first check the status:
git status
This shows what’s been changed. Stage your changes (prepare for commit):
git add filename
To add all changes at once:
git add .
Then record (commit) them:
git commit -m "Add login screen UI"
Write commit messages that clearly describe what you did. Avoid vague phrases like “update” or “fix.”
4. Push to GitHub
To share your local changes with the team, push to GitHub:
git push origin feature/feature-name
For the first push, use the -u flag so future pushes only need “git push”:
git push -u origin feature/feature-name
5. Pull Others’ Changes
To get changes that teammates added:
git pull
Always run this before starting work to ensure you have the latest version.
Common Mistakes and Solutions
Here are mistakes everyone makes during development and how to recover from them.
Mistake 1: Working on the Wrong Branch
If you worked on main when you should have been on a feature branch:
# Create the correct branch (preserving current state)
git branch feature/correct-branch-name
# Reset the wrong branch
git reset --hard HEAD~1
Before committing, this safer approach works better:
git stash # Temporarily save changes
git checkout -b feature/correct-branch-name
git stash pop # Restore changes
Mistake 2: Wrong Commit Message
To fix the most recent commit message:
git commit --amend -m "Correct message"
Only use this if you haven’t pushed yet.
Mistake 3: Forgot to Add a File to Commit
To add a file to the most recent commit:
git add forgotten-file
git commit --amend --no-edit
--no-edit means "don't change the message."
Mistake 4: Committed Sensitive Information
If you accidentally committed passwords or API keys, and haven’t pushed yet:
# Undo the last commit (keep changes)
git reset --soft HEAD~1
# Add sensitive file to .gitignore
echo ".env" >> .gitignore
# Remove sensitive info and recommit
git add .
git commit -m "Exclude environment file"
If you’ve already pushed, immediately revoke the key and completely remove it from history (requires advanced operations).
Mistake 5: Accidentally Deleted a File
If you deleted a committed file by mistake:
# Restore to last commit state
git checkout HEAD filename
To discard all uncommitted changes:
git restore .
Essential Knowledge: .gitignore
During development, many files shouldn’t be tracked by Git — configuration files with passwords or API keys, temporary files, build artifacts. To automatically ignore these, create a “.gitignore” file at your project root.
Basic .gitignore Example
# Environment variables (sensitive)
.env
.env.local
# Dependencies
node_modules/
vendor/
# Build output
dist/
build/
*.pyc
# OS-specific files
.DS_Store
Thumbs.db
# Editor settings
.vscode/
.idea/
# Log files
*.log
logs/
Language and framework-specific .gitignore templates are available from GitHub’s official repository (https://github.com/github/gitignore).
Ignoring Already-Tracked Files
If you added something to .gitignore but it’s still being tracked:
git rm --cached filename
git commit -m "Remove .env from tracking"
The --cached flag removes it from Git's tracking without deleting the actual file.
Team Development in Practice
Resolving Conflicts
When multiple people edit the same file, conflicts occur. After git pull, you'll see:
CONFLICT (content): Merge conflict in index.html
Open the file and you’ll see markers like this:
<<<<<<< HEAD
Your changes
=======
Someone else's changes
>>>>>>> branch-name
Manually edit this to keep only the correct code. After fixing:
git add index.html
git commit -m "Resolve conflict"
Conflicts aren’t scary. Just calmly compare both changes and decide which to keep (or combine both).
Pull Requests
When your work is complete, create a Pull Request (PR) on GitHub. This is essentially asking “please integrate my changes into the main branch.”
- Click the “Pull requests” tab on your repository page
- Click “New pull request”
- Describe your changes and click “Create pull request”
Team members review your code, and once approved, it’s merged into the main branch.
Emergency Recovery: git reflog
When everything seems ruined, git reflog is your savior. It records every operation you've performed with Git.
git reflog
Even deleted commits are recorded here. Once you find the state you want to return to:
git reset --hard commit-hash
Or create a new branch to preserve it:
git branch recovery-branch commit-hash
Practical Tips
- Commit frequently: Small, frequent commits minimize impact when problems arise
- Clear commit messages: Write what and why you changed
- Always pull before working: Get teammates’ changes before starting
- Never work directly on main: Always create a working branch
- Push regularly: Don’t accumulate changes locally — send to GitHub periodically
Why This Knowledge Lasts
Git’s fundamental design solves core problems in distributed version control, and its core hasn’t changed in nearly 20 years. The commands and concepts you learned today are explained identically in “Pro Git” (https://git-scm.com/book/en/v2), the standard textbook by Scott Chacon and Ben Straub, from its 2014 second edition to the present.
While tool UIs and services evolve, the basic needs of “recording changes,” “collaborating with teams,” and “reverting to the past” remain constant.
Resources for Further Learning
The Git official documentation (https://git-scm.com/docs) has detailed explanations of all commands. Atlassian’s .gitignore tutorial (https://www.atlassian.com/git/tutorials/saving-changes/gitignore) helps you understand ignore patterns.
When you’re stuck, Google the specific error message — you’ll almost certainly find a solution on Stack Overflow.
Start Now
After reading this article, get your hands dirty. Create a new folder, run git init, create a text file, and commit it. That's all it takes — you've started using Git.
Don’t fear mistakes. Git is a tool for recording changes, so any failure can be undone. The experience of trying, failing, and recovering is the best learning.
Begin your development journey. Accumulate commits, create branches, sometimes fail, and make Git your own.
References
- Git Official Site: https://git-scm.com/
- Git Official Documentation: https://git-scm.com/docs
- Pro Git (by Scott Chacon & Ben Straub): https://git-scm.com/book/en/v2
- GitHub Docs: https://docs.github.com/
- GitHub .gitignore Templates: https://github.com/github/gitignore
- Atlassian Git Tutorials: https://www.atlassian.com/git/tutorials
— –
If this was useful, follow me here on Medium.
I’m S — a content creator and AI practitioner based in rural Japan (Shimane Prefecture). I publish practical, honest takes on AI tools, content monetization, and what it actually looks like to build income with these tools from outside a major city.
[Follow →](https://medium.com/@johnpascualkumar077)
コメントを残す