Git & GitHub for Beginners: Complete Guide 2025
Git is non-negotiable for developers. Learn the essential commands, workflows, and collaboration techniques you'll use every day.
Key Takeaways
- Git is version control; GitHub is a hosting platform
- Commit early, commit often—good commits tell a story
- Always work in feature branches, never directly on main
- Pull requests are how teams review and merge code
1. Git Basics & Setup
What is Git?
Git is a distributed version control system. It tracks changes in your code, lets you collaborate with others, and provides a safety net to undo mistakes.
Initial Setup
# Configure your identity
git config --global user.name "Your Name"
git config --global user.email "you@email.com"
# Initialize a new repo
git init
2. Essential Commands
| Command | Purpose |
|---|---|
| git status | See changed files |
| git add . | Stage all changes |
| git commit -m "msg" | Save changes with message |
| git push | Upload to remote |
| git pull | Download latest changes |
| git log | View commit history |
3. Branching & Merging
Branches let you work on features without affecting the main codebase:
# Create and switch to new branch
git checkout -b feature/login-page
# Switch branches
git checkout main
# Merge branch into current
git merge feature/login-page
Branch Naming Conventions
feature/- new featuresbugfix/- bug fixeshotfix/- urgent production fixes
4. GitHub Workflow
The Standard Workflow
- Clone the repo:
git clone URL - Create a feature branch
- Make changes and commit
- Push your branch to GitHub
- Create a Pull Request (PR)
- Get code reviewed and merge
5. Collaboration
Pull Request Best Practices
- Keep PRs small and focused (one feature per PR)
- Write descriptive PR titles and descriptions
- Request reviews from relevant team members
- Respond to feedback constructively
6. Pro Tips
- Use .gitignore: Exclude node_modules, .env, and other files that shouldn't be tracked
- Commit frequently: Small, logical commits are easier to review and debug
- Pull before push: Always pull latest changes before pushing
- Learn to resolve conflicts: They're inevitable—don't fear them
Advanced Git Commands
| Command | Purpose |
|---|---|
| git stash | Temporarily save uncommitted changes |
| git stash pop | Restore stashed changes |
| git rebase main | Reapply commits on top of main |
| git cherry-pick <hash> | Apply a specific commit |
| git reset --hard HEAD~1 | Undo last commit (destructive) |
| git reflog | History of all Git operations |
| git bisect | Find commit that introduced bug |
Resolving Merge Conflicts
Conflicts happen when two branches modify the same lines. Here's how to handle them:
- Don't panic: Conflicts are normal
- Look for conflict markers: <<<<<<<, =======, >>>>>>>
- Choose which code to keep (or combine both)
- Remove the conflict markers
- Stage and commit: git add . && git commit
Common Git Mistakes
Committing directly to main
Always use feature branches. Protect main with branch rules.
Giant commits with vague messages
"Fixed stuff" tells nothing. Write descriptive commit messages.
Force pushing to shared branches
git push --force can destroy teammates' work. Never do it on shared branches.
Committing sensitive data
API keys, passwords, .env files should never be committed. Use .gitignore and check before every commit.
Not pulling before working
Always git pull before starting work. Prevents many conflicts.
Success Stories
"Git skills saved my internship interview..."
"Interviewer asked about my Git workflow. I explained branching, PRs, and code reviews. Got the job because I showed I could work in a team." — Rahul, IIT Bombay
"Green contribution graph got me noticed..."
"Made daily commits to my projects. Recruiter mentioned my GitHub activity during the interview. Showed consistency matters." — Priya, IIIT Hyderabad
"Learned to recover from disasters..."
"Accidentally deleted important code. Used git reflog to find the lost commit and restored everything. Git saved hours of work." — Karan, VIT Vellore
Frequently Asked Questions
What's the difference between Git and GitHub?
Git is the version control system (the tool). GitHub is a platform that hosts Git repositories online. Other alternatives include GitLab and Bitbucket.
How often should I commit?
Commit whenever you complete a logical unit of work. A good rule: if you can't describe the commit in one sentence, it's too big.
Should I use merge or rebase?
Merge is safer and preserves history. Rebase creates a cleaner history but can complicate things. For beginners, stick with merge.
How do I undo a commit?
Use git reset --soft HEAD~1 to undo but keep changes. Use git reset --hard HEAD~1 to completely remove (dangerous). git revert creates a new commit that undoes changes (safest).
What should go in .gitignore?
node_modules, .env files, build folders, IDE settings (.idea, .vscode), OS files (.DS_Store), and any generated files.
How do I contribute to someone else's repo?
Fork the repo to your account, clone your fork, make changes, push to your fork, then create a Pull Request to the original.
Git Mastery Checklist
GitHub Profile Optimization
- Add a profile README: Create a repo named your username with a README.md that shows on your profile
- Pin your best repos: Showcase 6 projects that demonstrate your skills
- Keep your contribution graph green: Regular commits show consistency
- Write good READMEs: Every project should have clear documentation
- Add project descriptions: One-line summaries help visitors understand
Master Git for Your Career
Git is used in virtually every tech company. The more comfortable you are with it, the more effective you'll be as a developer.
Remember: everyone struggles with Git at first. The important thing is to keep practicing, and don't be afraid to make mistakes—that's what version control is for!
Start using Git in all your projects. Practice makes perfect. 🚀
📚 Related Resources
Written by Sproutern Career Team
Practical Git knowledge for aspiring developers.
Last updated: December 14, 2025