Git is non-negotiable for developers. Learn the essential commands, workflows, and collaboration techniques you'll use every day.
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.
# Configure your identity
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
# Initialize a new repo
git init
| 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 |
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
feature/ - new featuresbugfix/ - bug fixeshotfix/ - urgent production fixesgit clone URL| 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 |
Conflicts happen when two branches modify the same lines. Here's how to handle them:
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.
"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
Git is the version control system (the tool). GitHub is a platform that hosts Git repositories online. Other alternatives include GitLab and Bitbucket.
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.
Merge is safer and preserves history. Rebase creates a cleaner history but can complicate things. For beginners, stick with merge.
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).
node_modules, .env files, build folders, IDE settings (.idea, .vscode), OS files (.DS_Store), and any generated files.
Fork the repo to your account, clone your fork, make changes, push to your fork, then create a Pull Request to the original.
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. 🚀
Written by Sproutern Career Team
Practical Git knowledge for aspiring developers.
Regularly updated