Complete Git Flow Guide
1. Git Basics
git init # Initialize a Git repository
git clone <repo-url> # Clone a repository
git status # Show the working directory status
git add <file> # Stage a file
git commit -m "msg" # Commit staged changes
git push # Push changes to remote
git pull # Pull latest changes from remote
2. Branching Strategy
- main/master: Production-ready code
- develop: Integration branch (optional)
- feature/*: New features
- bugfix/*: Minor fixes
- hotfix/*: Critical fixes in production
- release/*: Release preparation
3. Git Workflow
1. Clone the Repository
git clone git@repo-url
cd repo
2. Create a Feature Branch
git checkout -b feature/your-feature-name
3. Work & Commit Frequently
git add .
git commit -m "Describe what you did"
4. Sync with Remote Develop/Main
git fetch origin
git rebase origin/main
5. Push Your Branch
git push origin feature/your-feature-name
6. Create a Pull Request (PR)
Use GitHub/GitLab UI
7. After PR Approval
git checkout main
git pull origin main
Complete Git Flow Guide
git merge feature/your-feature-name
git push origin main
8. Clean Up
git branch -d feature/your-feature-name
git push origin --delete feature/your-feature-name
4. Hotfix Flow
git checkout -b hotfix/critical-fix main
# Make fixes
git commit -am "Quick production fix"
git checkout main
git merge hotfix/critical-fix
git push origin main
5. Release Flow
git checkout -b release/v1.2.0 develop
# Final testing, version bump, etc.
git checkout main
git merge release/v1.2.0
git tag v1.2.0
git push origin main --tags
6. Git Rebase vs Merge
merge: Preserves commit history.
rebase: Cleaner linear history.
git checkout feature/xyz
git fetch origin
git rebase origin/main
7. Cleaning Up
git branch -d old-feature
git remote prune origin
8. Undoing Mistakes
Unstage: git reset HEAD <file>
Complete Git Flow Guide
Amend: git commit --amend
Log: git log --oneline --graph
9. Git Tags for Releases
git tag -a v1.0 -m "Release v1.0"
git push origin v1.0
10. Advanced Tools
.gitignore: Ignore files
.gitattributes: Text/binary file rules
git stash: Temporarily save changes
git cherry-pick: Apply specific commits