Working together on a project can get pretty chaotic. That's where GitFlow comes in 😎!
GitFlow is a simple set of branching and merging rules for better collaboration, less errors and code conflicts. It's easy to pick up and adapt to your own team's needs.
In GitFlow, the main branches are:
1. Main branch: production-ready code. This is where the working version of your project is stored.
2. Develop branch: created from the main branch, it is used for integration and testing of new features or improvements.
3. Feature branches: each new feature/change should be developed on a separate feature branch created from the develop branch, and then merged back into it when ready.
More complex projects might also include:
4. Release branches: created from the develop branch, they allow for final testing, bug fixes, without affecting ongoing development.
5. Hotfix branches: created from the main branch, to fix critical issues or bugs in production.
HowTo GitFlow branching:
Let's say I've created a new repo with a branch main.
1- create a develop branch and switch to it:
git checkout -b develop
2- push the develop branch to the remote repository (if needed):
git push -u origin develop
3- while in the develop branch, create a feature branch and switch to it:
git checkout -b feature/your-feature-name
4- push the feature branch to the remote repository (if needed):
git push -u origin feature/your-feature-name
⚠ Remember to send your feature branch PRs (pull requests) to the develop branch and not main, and develop branch PRs to the main branch (or a release branch).
Sometimes you might find develop or feature branches being X commits behind main. It happens when people forget to update the development branches after successfully merging PR(s) into main. The develop and feature branches should be kept up-to-date to:
- reduce the chance of merge conflicts
- detect integration issues early on
- and for consistency 👍
So make sure to merge changes from the main branch into your develop and feature branches 😀!
Common Git branching commands:
- get a list of all branches:
git branch
- create a new branch:
git branch your-branch-name
- switch to an existing branch:
git checkout your-branch-name
- create a new branch and switch to it:
git checkout -b your-branch-name
- delete a branch:
git branch -d your-branch-name
- push a branch to a remote repository:
git push origin your-branch-name
- cloning a specific branch from a remote repository:
git clone -b your-branch-name your-repository-url
Top comments (0)