The Git flow workflow defines a strict branching model designed around the project release. The main components are:
- Main (or Master): This branch contains production-ready code.
- Develop: This branch contains features that are ready for the next release.
- Feature branches: Branches created for new features or issues.
- Release branches: Branches that prepare the next production release.
- Hotfix branches: Branches that quickly patch production releases.
Ensure you have the latest version of your repo:
git clone https://github.com/juanjaragavi/juan-jaramillo-api-endpoints.git
cd juan-jaramillo-api-endpoints
- Open GitHub Desktop.
- Click on
File
>Clone Repository
. - Choose the
URL
tab and enter the repository's URL, then clickClone
.
git checkout develop
git pull origin develop
git checkout -b feature/your-feature-name
- Make sure you are on the
develop
branch. - Fetch the latest changes.
- Click the
Current Branch
dropdown and chooseNew Branch
, name itfeature/your-feature-name
.
After finishing the development and testing of your feature:
git add .
git commit -m "Completed feature/your-feature-name"
git push origin feature/your-feature-name
- Make your changes and then click on
Commit to feature/your-feature-name
. - Click the
Publish Branch
button to push your feature branch to the remote.
git checkout develop
git pull origin develop
git checkout -b release/vX.Y.Z
- Make sure you're on the
develop
branch. - Fetch the latest changes.
- Click the
Current Branch
dropdown and chooseNew Branch
, name itrelease/vX.Y.Z
.
After final testing:
git checkout main
git merge release/vX.Y.Z
git push origin main
git checkout develop
git merge release/vX.Y.Z
git push origin develop
git branch -d release/vX.Y.Z
- Change to the
main
branch. - Choose
Merge into Current Branch
under theBranch
menu and select your release branch. - Push the changes to
main
. - Repeat the merge process for the
develop
branch. - Delete the release branch by right-clicking it in the
Current Branch
dropdown.
Hotfixes are branches that derive from main
and are meant to fix critical issues.
git checkout main
git pull origin main
git checkout -b hotfix/your-hotfix-name
- Make sure you're on the
main
branch. - Fetch the latest changes.
- Click the
Current Branch
dropdown and chooseNew Branch
, name ithotfix/your-hotfix-name
.
After the hotfix is tested:
git checkout main
git merge hotfix/your-hotfix-name
git push origin main
git checkout develop
git merge hotfix/your-hotfix-name
git push origin develop
git branch -d hotfix/your-hotfix-name
- Change to the
main
branch. - Choose
Merge into Current Branch
under theBranch
menu and select your hotfix branch. - Push the changes to
main
. - Repeat the merge process for the
develop
branch. - Delete the hotfix branch by right-clicking it in the
Current Branch
dropdown.
Note: Ensure you regularly merge develop
into your feature branches to avoid large merge conflicts.
To revert all changes made in the develop
branch and make it identical to the main
branch using the Git flow strategy, you can follow these steps:
-
Make sure you're in the
develop
branch:git checkout develop
-
Fetch the latest changes: This ensures you have the latest state of both
develop
andmain
branches.git fetch
-
Reset the
develop
branch to themain
branch:git reset --hard origin/main
This command will make the
develop
branch's pointer point to the same commit asmain
branch's pointer, effectively discarding all changes indevelop
since it diverged frommain
. -
Push the changes to the remote repository: Since you've rewritten the history of the
develop
branch, you'll need to forcefully push the changes to the remote repository.git push origin develop --force
โ ๏ธ Be cautious when using--force
as it can overwrite changes on the remote that you don't have locally. It's good practice to communicate with your team before performing such actions to ensure no work is lost.
Now, the develop
branch will be in the exact same state as the main
branch.
Remember to always backup or ensure you have other means to recover your work before performing destructive operations like these.
To switch to the main
branch, you simply use the git checkout
command. Here's how you can do it:
git checkout main
If you're using Git version 2.23 or later, you can also use the git switch
command, which is more intuitive for this kind of task:
git switch main
After running either of these commands, you'll be on the main
branch. You can confirm this by running:
git branch
The currently active branch will be indicated with an asterisk (*) next to its name.