Problem without branches:
mainSolution: Branches!
main = always stablefeature-login = you develop the loginfeature-api = a colleague develops the APIhotfix-bug = urgent fixEach in their own corner, merge when it is ready!
mkdir demo-branches && cd demo-branches
git init
# Starting base
echo "print('App v1.0')" > app.py
git add . && git commit -m "Initial version"
# Create and switch to a new branch
git checkout -b feature-login
echo "print('Login system')" > login.py
git add . && git commit -m "Add login"
# Go back to main
git checkout main
echo "print('App v1.1')" > app.py
git add . && git commit -m "Update main"
# See all branches
git branch --all
# Merge the feature
git merge feature-loginResult: Both developments are combined!
MERGE:
git merge feature-branch # Creates a merge commitREBASE:
git rebase main # "Moves" your commits after mainRecommendation: Start with MERGE!
| Command | Action |
|---|---|
git branch | List the branches |
git checkout -b <name> | Create + switch to a branch |
git checkout <name> | Switch branch |
git merge <branch> | Merge a branch |
git branch -d <name> | Delete a branch |
git push origin <name> | Push a branch |
Simple and effective workflow:
New feature:
git checkout main
git pull
git checkout -b feature-nouvelle-fonctionnaliteDevelop:
# Code, code, code...
git add .
git commit -m "Feature finished"Merge:
git checkout main
git merge feature-nouvelle-fonctionnalite
git branch -d feature-nouvelle-fonctionnalite # Clean upThat's all! Branches = Organization and Cleanliness.