Branches: Create, Switch, Push, Merge, & Delete
Master Git Branching for Professional Development Workflows
Git branches enable parallel development workflows, allowing multiple developers to work on different features simultaneously without conflicts. This fundamental concept separates amateur from professional development practices.
Core Git Branch Benefits
Parallel Development
Work on multiple features simultaneously without interfering with the main codebase. Switch between different development contexts instantly.
Safe Experimentation
Test new ideas and approaches without risk to production code. Easily discard failed experiments or merge successful ones.
Team Collaboration
Multiple developers can contribute to the same project without stepping on each other's work. Merge changes when ready.
Every Git command you execute operates within the context of your current branch. Always verify which branch you're on before committing, pushing, or pulling to avoid unintended changes to the wrong branch.
Identifying Your Current Branch in VS Code
Locate Branch Indicator
Look at the bottom left corner of the Visual Studio Code window where the current branch name is displayed
Verify Branch Context
The default branch name is typically 'master' but confirm you're on the intended branch before making changes
Creating a New Branch in VS Code
Access Branch Menu
Click the current branch name at the bottom left of VS Code window to open the branch selection panel
Select Create Option
Choose '+ Create new branch' from the panel that appears at the top of the window
Name Your Branch
Type a descriptive name for your new branch and press Return (Mac) or Enter (Windows) to create it
Start Working
You're now on the new branch and ready to make commits specific to this development context
Local Branch Switching Checklist
Opens the branch selection panel at the top of the window
All locally available branches will be listed for selection
Click the branch you want to switch to and VS Code will change your working context
Fetch vs Pull Operations
| Feature | Fetch | Pull |
|---|---|---|
| Data Download | Downloads new data from remote | Downloads new data from remote |
| Local Integration | Does not merge into files | Merges data into your files |
| Working Directory | Leaves files unchanged | Updates your working files |
| Safety Level | Safe, non-destructive | Can create merge conflicts |
Branch Merging Process
Switch to Target Branch
Navigate to the branch that will receive the merged changes, typically the master branch
Verify Clean State
Ensure Source Control panel shows no uncommitted changes that need to be committed first
Access Merge Options
Click More Actions button in Source Control panel, then select Branch > Merge Branch from the menu
Select Source Branch
Choose the branch you want to merge into your current branch and confirm the merge operation
Merging branches may result in conflicts when the same code has been modified in different ways. Be prepared to resolve conflicts manually when they occur during the merge process.
Safe Branch Deletion Process
You cannot delete the branch you're currently working on
Click the More Actions button to reveal additional branch management options
Select the deletion option from the nested branch management menu
Choose the specific branch to delete and confirm the permanent removal
Key Takeaways
