0
0
Gitdevops~10 mins

Feature branch workflow in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Feature branch workflow
Start on main branch
Create feature branch
Work on feature branch
Commit changes
Push feature branch to remote
Open Pull Request
Code Review & Approve
Merge feature branch into main
Delete feature branch
Update local main branch
End
This flow shows how a developer creates a separate branch for a feature, works on it, pushes it, and merges it back to main after review.
Execution Sample
Git
git checkout -b feature/login
# work on login feature
git add .
git commit -m "Add login feature"
git push origin feature/login
git checkout main
git merge feature/login
This code creates a feature branch, commits changes, pushes it, then merges it back to main.
Process Table
StepCommandActionBranchResult
1git checkout -b feature/loginCreate and switch to feature branchfeature/loginSwitched to new branch 'feature/login'
2git add .Stage changesfeature/loginChanges staged for commit
3git commit -m "Add login feature"Commit staged changesfeature/loginCommit created with message 'Add login feature'
4git push origin feature/loginPush feature branch to remotefeature/loginBranch 'feature/login' pushed to remote
5git checkout mainSwitch back to main branchmainSwitched to branch 'main'
6git merge feature/loginMerge feature branch into mainmainFeature branch merged into main
7git branch -d feature/loginDelete local feature branchmainDeleted branch 'feature/login'
8git push origin --delete feature/loginDelete remote feature branchmainDeleted remote branch 'feature/login'
💡 Feature branch merged and deleted, main branch updated with feature
Status Tracker
VariableStartAfter Step 1After Step 4After Step 6Final
Current Branchmainfeature/loginfeature/loginmainmain
Feature Branch Exists LocallyNoYesYesYesNo
Feature Branch Exists RemotelyNoNoYesYesNo
Main Branch UpdatedNoNoNoYesYes
Key Moments - 3 Insights
Why do we create a new branch instead of working directly on main?
Creating a feature branch isolates your work so main stays stable. See Step 1 where we switch to 'feature/login' branch before making changes.
What happens if you forget to push your feature branch?
Your changes stay local and others can't see them. Step 4 shows pushing the branch to remote, which shares your work.
Why delete the feature branch after merging?
To keep the repository clean and avoid confusion. Steps 7 and 8 show deleting local and remote feature branches after merge.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the current branch after Step 4?
Afeature/login
Bmain
Cdevelop
DNone
💡 Hint
Check the 'Current Branch' row in variable_tracker after Step 4
At which step is the feature branch merged into main?
AStep 3
BStep 6
CStep 2
DStep 8
💡 Hint
Look at the 'Action' column in execution_table for merging
If you skip Step 7 (deleting local branch), what happens?
ARemote branch is deleted automatically
BMain branch is deleted
CLocal feature branch remains, possibly causing confusion
DFeature branch is merged again
💡 Hint
Refer to Step 7 in execution_table and variable_tracker for branch existence
Concept Snapshot
Feature Branch Workflow:
- Start on main branch
- Create feature branch: git checkout -b feature/name
- Work and commit on feature branch
- Push feature branch: git push origin feature/name
- Open PR and merge into main
- Delete feature branch locally and remotely
- Update local main branch
Keeps main stable and isolates features.
Full Transcript
The Feature Branch Workflow starts by creating a new branch from main to work on a feature separately. You switch to this new branch, make changes, stage and commit them. Then you push the feature branch to the remote repository so others can see your work. After review, you merge the feature branch back into main. Finally, you delete the feature branch locally and remotely to keep the repository clean. This workflow helps keep the main branch stable and organized.