- Understanding Git Basics
- Essential Git Commands
- Working with Remote Repositories
- Branching and Merging
- Undoing Changes and Recovery
- Tags and Version Releases
- Common Development Scenarios
- Common Pitfalls and How to Avoid Them
- Using SSH with GitHub (Recommended)
- Git Best Practices
- Conclusion
Understanding Git Basics
Working Directory
This is where you actually edit files on your local machine.
Staging Area (Index)
A buffer between your working directory and the repository.
You decide what exactly goes into the next commit.
Repository
The database that stores all commit history.
Typical workflow:
1 | Working Directory → Staging Area → Local Repository → Remote Repository |
Once this flow makes sense, Git becomes much easier.
Essential Git Commands
Initial Setup
1 | git config --global user.name "Your Name" |
Initialize a repository:
1 | git init |
Cloning a Repository
1 | # HTTPS |
SSH (recommended)
1 | git clone git@github.com:username/repo.git |
Tracking and Committing Changes
1 | git status |
View history
1 | git log --oneline |
Recommended commit prefixes
feat: new featurefix: bug fixdocs: documentationrefactor: refactoring
Working with Remote Repositories
1 | git remote add origin <repo-url> |
Avoid force push unless you know exactly what you’re doing:
1 | git push --force-with-lease |
Branching and Merging
Branches allow safe experimentation.
1 | git branch |
Recommended branch naming
- main – stable production
- feature/* – new features
- hotfix/* – urgent fixes
Undoing Changes and Recovery
Git is powerful because almost nothing is truly lost.
1 | git reset --soft <commit> |
Tags and Version Releases
1 | git tag -a v1.0 -m "First release" |
Tags are ideal for marking stable releases.
Common Development Scenarios
New Project Push
1 | git init |
Team Feature Development
1 | git checkout -b feature/payment |
Hotfix Production Bug
1 | git checkout main |
Common Pitfalls and How to Avoid Them
- Forgot git add
- Merge conflicts ignored
- Panic after git reset –hard
- Using password instead of token/SSH
Tip: If something goes wrong, stop and check git reflog.
Using SSH with GitHub (Recommended)
1 | ssh-keygen -t ed25519 -C "you@example.com" |
Successful output:
1 | Hi username! You've successfully authenticated. |
Git Best Practices
Commit small, meaningful changes
Write clear commit messages
Use branches aggressively
Clean unused branches regularly
Prefer SSH over HTTPS
Use fine-grained tokens for automation
Conclusion
You don’t need to memorize every Git command.
Git is not about commands—it’s about understanding history and collaboration.
Once you understand the workflow, Git becomes a powerful safety net rather than a source of anxiety.