Welcome to branch-management
This is an auto-generated documentation file.
Git Branch Management
Branch management is a core part of using Git effectively. It includes creating, switching, renaming, and deleting branches.
1. Viewing Branches
List all local branches:
git branch
See the latest commit on each branch:
git branch -v
See remote branches:
git branch -r
See both local and remote:
git branch -a
2. Creating a Branch
Create a new branch from your current HEAD:
git branch <branch-name>
3. Switching Branches
Move to another branch:
git switch <branch-name>
Alternative:
git checkout <branch-name>
4. Create and Switch Simultaneously
Use -c to create and switch in one step:
git switch -c <branch-name>
5. Deleting Branches
Delete a local branch (safe delete):
git branch -d <branch-name>
Force delete if the branch is not merged:
git branch -D <branch-name>
Delete a remote branch:
git push origin --delete <branch-name>
6. Renaming Branches
Rename the current branch:
git branch -m <new-name>
Rename another branch:
git branch -m <old-name> <new-name>
7. Typical Branch Workflow
- Start from
mainormaster - Create a new branch for your feature or fix
- Make and commit changes on the branch
- Merge it back when done
- Optionally delete the branch if it’s no longer needed