Overview
Branches are fundamental to Git workflows, allowing you to develop features, fix bugs, and experiment without affecting the main codebase. GitHub Desktop makes branch management intuitive and visual.Create Branches
Switch Branches
Merge Branches
Track Remote
Understanding Branches
Branch Basics
A branch is a pointer to a specific commit in your repository’s history. Branches allow you to:- Develop features in isolation
- Fix bugs without affecting production code
- Experiment with new ideas safely
- Collaborate with others on specific changes
Default Branch
Every repository has a default branch (usuallymain or master):
- New commits are made to this branch by default
- Pull requests typically merge into this branch
- The default branch represents the production or stable code
Creating Branches
Create from Current Branch
Open Branch Menu
Click New Branch
Name the Branch
feature/add-login, fix/crash-on-startup)Create Branch
Create from Specific Commit
Open History
Find Commit
Right-Click Commit
Name and Create
Branch Creation Implementation
--no-track to prevent accidentally pushing to the fork’s upstream.Switching Branches
Switch to Existing Branch
Open Branch List
Select Branch
- Click a branch to switch to it
- Or search for a branch by typing
Handle Uncommitted Changes
- Bring changes: Move changes to the new branch
- Stash changes: Save changes for later
- Cancel: Return to current branch
Automatic Stashing
When switching branches with uncommitted changes:- GitHub Desktop automatically creates a stash
- Switches to the target branch
- Attempts to apply the stash
- If conflicts occur, leaves the stash for manual application
Branch List Organization
The branch dropdown organizes branches into sections:Default Branch
- Shows the repository’s default branch at the top
- Usually
mainormaster
Recent Branches
- Branches you’ve worked on recently
- Sorted by last checkout time
Other Branches
- All other local branches alphabetically
Pull Request Branches
- Branches associated with open pull requests
- Grouped by PR status
Remote Branches
- Branches on the remote that don’t exist locally
- Can be checked out with one click
Renaming Branches
Rename the current branch or any other branch:Open Branch Menu
Find Branch to Rename
Select Rename
Enter New Name
Rename
Rename Implementation
Deleting Branches
Delete Local Branch
Open Branch Menu
Find Branch
Delete
Confirm
Delete Remote Branch
View Remote Branches
Right-Click Remote Branch
Delete on Remote
Confirm
Delete Implementation
Merging Branches
Merge into Current Branch
Switch to Target Branch
main)Open Branch Menu
Select Source Branch
Review Merge Info
- Number of commits to merge
- Potential conflicts detected
Merge
Merge Strategies
GitHub Desktop uses standard Git merge strategies:- Fast-forward: When possible, simply moves the branch pointer forward
- Merge commit: Creates a new merge commit when branches have diverged
- Conflict resolution: Stops and asks for manual resolution when conflicts occur
Comparing Branches
View differences between branches:Open Branch Menu
Select Branch
Review Differences
- Commits that differ between branches
- Files changed
- Line-by-line diffs
Branch Status Indicators
Branches in the list show visual indicators:- Ahead/Behind: Shows how many commits ahead or behind the upstream
- Current Branch: Bold text and checkmark icon
- Default Branch: Star icon
- Published: Cloud icon indicates the branch exists on remote
- PR Indicator: Icon shows if there’s an associated pull request
Finding Merged Branches
Identify branches that have been fully merged:Upstream Tracking
Publishing Branches
Publish a local branch to the remote:Create or Switch to Branch
Click Publish
Confirm
Setting Upstream
When publishing a branch, GitHub Desktop automatically:- Pushes the branch to
origin - Sets up upstream tracking with
--set-upstream - Enables pull/push for the branch
Branch Naming Conventions
Common branch naming patterns:Protected Branches
When working with protected branches on GitHub:- Force push blocked: Cannot force push to protected branches
- Review required: May require pull request reviews before merging
- Status checks: CI/CD checks must pass before merging
- Admin bypass: Repository admins may have special permissions
Best Practices
- Use Descriptive Names: Branch names should clearly indicate their purpose
- Keep Branches Short-Lived: Merge or delete branches after completing work
- Update from Main Regularly: Keep feature branches up to date with the default branch
- Delete Merged Branches: Clean up branches after merging to avoid clutter
- Don’t Commit to Main Directly: Use feature branches for all changes
- Use Prefixes: Organize branches with prefixes like
feature/,fix/,docs/
Keyboard Shortcuts
Troubleshooting
Cannot Switch Branches
Cannot Switch Branches
- Uncommitted changes conflict: Commit, stash, or discard changes
- Unmerged files: Resolve merge conflicts before switching
- Detached HEAD: Create a branch from current commit first
Branch Deleted by Mistake
Branch Deleted by Mistake
- Find the commit SHA in the History tab
- Create a new branch from that commit
- Or use
git reflogin terminal to find the deleted branch’s tip
Merge Conflicts
Merge Conflicts
- GitHub Desktop highlights conflicted files
- Resolve conflicts in your editor or using the conflict resolver
- Stage resolved files and complete the merge
- See Merge Conflicts for detailed help
Cannot Delete Branch
Cannot Delete Branch
- It’s the currently checked out branch (switch first)
- It has unmerged commits (use
-Dflag to force) - It’s the default branch for the repository