Collaborating on a big software project can be exciting, but it can also become chaotic if no one follows a proper workflow. Imagine merging someone’s code only to find it breaks half the app. Or worse, accidentally overwriting your teammate’s work. That’s where Git best practices come in.
Here’s a friendly guide to help you push code safely and respectfully when working on a shared project.
Don’t Work Directly on the main branch
The main (or production) branch is like your project’s home base—it should always be stable. Instead of pushing code directly there, create a new branch for each task you’re working on.
git checkout main
git pull origin main
git checkout -b feature/add-user-profile
Give your branch a clear name like feature/login-form or bugfix/navbar-crash.
Commit Frequently and Clearly
Don’t dump 300 lines of code in one big commit. Instead, break your work into logical chunks and commit each one with a clear message:
git add .
git commit -m "feature: add login form with validation"
Good commit messages tell the story of your work.
Pull Before You Push
Before you push your changes, always make sure your branch is up to date with the latest changes from main (or develop):
git fetch origin
git rebase origin/main # or origin/staging
# or use `git pull --rebase origin main` to avoid merge commits
This prevents painful merge conflicts later. If there are conflicts, fix them locally before pushing.
Push Your Branch
Once your work is ready:
git push origin feature/add-user-profile
This doesn’t affect the main branch—it just puts your branch online so others can review it.
Open a Pull Request
Go to your Git hosting platform (like GitHub/GitLab/Bitbucket) and open a pull request (PR, aka Merge Request). Describe what your code does and why you made certain decisions. This is where teammates can leave feedback and approve your changes.
Be open to reviews—it’s part of working as a team.
Only Merge After Approval
Once your PR is reviewed and approved, you can merge it into the main branch. Depending on your team’s rules, you might:
- Squash your commits
- Rebase before merging
- Or let someone else do the merge
After that, feel free to delete your branch—it keeps things tidy.
Keep the main branch Updated Locally
Don’t forget to pull the latest main regularly:
git checkout main
git pull origin main
This way, you’re always working with the latest code.
Bonus Tips
- Use clear branch names: feature/, bugfix/, hotfix/
- Link PRs to tasks or issues
- Never commit secrets or large files
- Communicate with your team—always!
Final Thoughts
The goal of these habits isn’t to slow you down—it’s to help the whole team work faster without stepping on each other’s toes. Once you get used to this flow, pushing code becomes smooth, safe, and collaborative.
Got your next feature ready? Branch out, code clean, and open that PR with confidence.