A Fresher's Guide to Git and GitHub: Beyond Push and Pull
By Job Searchers Team
If you ask any senior engineer what the most important non-programming skill a junior developer can learn, the answer is almost always the same: Git.
In university or coding bootcamps, you likely learned the holy trinity of Git commands: git add ., git commit -m "update", and git push. If you were working on solo projects, this was perfectly sufficient. You used GitHub as a glorified Google Drive for your code.
However, the moment you join a production team with 10 other engineers touching the same codebase, that workflow will result in absolute chaos. Overwriting a coworker's work, resolving massive merge conflicts, and accidentally pushing broken code to the main branch are rites of passage for freshers.
To survive in a professional engineering environment, you need to move beyond push and pull. Here is the fresher’s guide to mastering Git for collaborative development.
1. Branching Strategies: Never Commit to Main
When working on a solo project, committing directly to the main (or master) branch is fine. In a corporate environment, doing this is a massive red flag (and usually blocked by repository settings anyway).
The Golden Rule: The main branch must always contain stable, production-ready code.
Whenever you pick up a new Jira ticket or task, you must create a new branch.
- Command:
git checkout -b feature/login-page(orgit switch -c feature/login-page).
Branch Naming Conventions
Use descriptive names so your team knows what you are working on. Standard prefixes include:
feature/for new additions (e.g.,feature/add-stripe-payment)bugfix/for resolving issues (e.g.,bugfix/fix-header-alignment)hotfix/for urgent production crashes.
2. The Art of the Commit Message
git commit -m "fixed stuff" is unacceptable in a professional setting.
Six months from now, when a bug appears and a senior engineer uses git blame to figure out who wrote the broken line of code, they need to know why that code was written. Your commit message provides that historical context.
A good commit message structure:
- Subject Line: Max 50 characters, written in the imperative mood. (e.g., "Add Google OAuth login button").
- Body (Optional but recommended): Explain what and why, not how. The code explains how. The commit message explains the business logic or reasoning behind it.
Example:
Fix database connection timeout error
Increased the connection timeout threshold from 5s to 15s.
This resolves the issue where users on slow mobile networks
were dropping connection during the checkout process.
3. Git Stash: The "Hold That Thought" Command
Imagine you are halfway through building a complex feature. Your code is broken and won't compile. Suddenly, your manager messages you: "Critical bug in production! We need you to fix it right now."
You can't commit your broken code, and you can't switch branches without committing or discarding your changes. What do you do?
Enter git stash.
git stash takes your uncommitted changes and saves them on a temporary clipboard, returning your working directory to a clean state.
- Run
git stash(Your messy code is hidden). - Switch to the
mainbranch and fix the urgent bug. - Switch back to your feature branch.
- Run
git stash pop(Your messy code is restored exactly as you left it).
4. Understanding Merge Conflicts (And Not Panicking)
Merge conflicts strike fear into the hearts of junior developers. A merge conflict simply means that you and another developer edited the exact same lines in a file, and Git doesn't know whose changes to keep.
How to handle them:
- Don't panic. You haven't broken the repository.
- Open your IDE. VS Code has excellent built-in merge conflict resolution tools.
- Look for the markers: Git will inject
<<<<<<<,=======, and>>>>>>>into the file. The code above the equals signs is usually your code; the code below is the incoming code. - Make a decision. Choose whether to keep your changes, their changes, or manually combine both.
- Delete the markers.
- Save the file,
git add, andgit committo finalize the resolution.
Pro-tip: The best way to avoid massive merge conflicts is to pull the main branch into your feature branch frequently (e.g., every morning). Small, daily conflicts are much easier to resolve than one giant conflict at the end of a two-week sprint.
5. Git Rebase: Keeping History Clean
If you submit a Pull Request and a senior engineer says, "Can you rebase this against main?", do you know what to do?
git merge main takes the new commits from main and creates a brand new "merge commit" in your branch. If you do this often, your Git history looks like a messy spiderweb.
git rebase main takes your unique commits, temporarily removes them, updates your branch with the latest code from main, and then reapplies your commits on top. This results in a clean, straight, linear project history.
Warning: Never run git rebase on a branch that you are sharing with other developers. Only rebase your personal feature branches.
Conclusion
Git is a complex, incredibly powerful tool that takes years to fully master. You don't need to know every single command to be an effective junior developer, but moving beyond the basics is essential.
By utilizing proper branching strategies, writing clear commit messages, and understanding how to navigate stashes and conflicts, you will save yourself (and your senior engineers) countless hours of headaches.
Stop fearing the terminal and start exploring what Git can really do.
Ready to Level Up Your Career?
Whether you need a resume that beats the ATS or a killer portfolio, our Premium Services can help you stand out.
Explore Premium Services