1.5 KiB
1.5 KiB
Git Workflow Best Practices
Git is an essential tool for modern software development. Here are some best practices for an effective Git workflow.
Branching Strategy
Main Branches
- main/master: Production-ready code
- develop: Integration branch for features
Supporting Branches
- feature/: New features
- bugfix/: Bug fixes
- hotfix/: Urgent production fixes
Commit Messages
Good commit messages are crucial:
Add user authentication system
- Implement JWT token generation
- Add login and logout endpoints
- Create user session middleware
Follow the 50/72 rule:
- First line: 50 characters or less
- Body: Wrap at 72 characters
Commands
Creating a Feature Branch
git checkout -b feature/new-feature develop
Committing Changes
git add .
git commit -m "Add feature description"
Merging
git checkout develop
git merge --no-ff feature/new-feature
git branch -d feature/new-feature
Tips
- Commit Often: Make small, logical commits
- Pull Regularly: Stay in sync with the team
- Review Before Commit: Use
git diffto check changes - Use .gitignore: Don't commit build artifacts or secrets
Advanced Features
Interactive Rebase
Clean up commit history:
git rebase -i HEAD~3
Stashing
Save work in progress:
git stash
git stash pop
Cherry-pick
Apply specific commits:
git cherry-pick <commit-hash>
Master Git, and you'll be a more effective developer!