Utilize common version control operations with Git
📘Cisco DevNet Associate (200-901 DEVASC)
1. What is a Git Branch?
A branch in Git is like a separate workspace or timeline for your code.
- It allows you to work on a new feature, bug fix, or experiment without affecting the main code.
- Think of it as a parallel path where you can make changes safely.
Key points for the exam:
- The default branch is usually called
mainormaster. - You can create multiple branches to work on different tasks simultaneously.
2. Why Branches are Important
- Isolate work: Your new code doesn’t break existing code in
main. - Collaboration: Multiple developers can work on different branches at the same time.
- Experiment safely: Test new ideas without risk to the stable codebase.
- Prepare for deployment: You can merge a tested branch into
mainwhen ready.
3. Common Git Branch Commands
Here are the commands you must know for the exam:
- View all branches
git branch
- Shows a list of branches. The current branch has an asterisk (*) next to it.
- Create a new branch
git branch <branch_name>
- Example:
git branch feature-login
- Creates a branch called
feature-loginbut does not switch to it yet.
- Switch to a branch
git checkout <branch_name>
- Example:
git checkout feature-login
- Now you are working inside the
feature-loginbranch.
- Create and switch in one command
git checkout -b <branch_name>
- Example:
git checkout -b feature-login
- This creates
feature-loginand switches to it immediately.
- Merge a branch into another
git checkout main
git merge <branch_name>
- Example:
git checkout main
git merge feature-login
- This takes all the changes from
feature-loginand integrates them intomain.
- Delete a branch
git branch -d <branch_name>
- Example:
git branch -d feature-login
- Deletes the branch after its changes are merged.
- If not merged yet, Git will warn you. Use
-Dto force delete if needed.
4. Branching Workflow in IT
In an IT environment, branches are used to organize development. Common strategies:
- Feature Branching
- Each new feature has its own branch.
- Example:
feature-api-authentication,feature-ui-dashboard.
- Bug Fix Branches
- Quick fixes go into separate branches.
- Example:
bugfix-login-error.
- Release Branches
- Prepare a stable release.
- Example:
release-v1.2.
- Hotfix Branches
- Urgent fixes to production.
- Example:
hotfix-critical-security.
Tip for exam: Know that branches help parallelize development and keep main stable.
5. Visualizing Branches
- The
git log --oneline --graph --allcommand shows branches in a tree-like diagram. - It’s helpful to see where branches diverge and merge.
Example command:
git log --oneline --graph --all
6. Best Practices
- Name branches clearly:
feature-login,bugfix-auth-error. - Keep branches small and focused for easier merging.
- Regularly merge main into your branch to stay updated.
- Delete branches after merging to keep the repository clean.
7. Exam Tips
- Understand what a branch is and why it is used.
- Memorize the basic branch commands:
git branch→ list branchesgit branch <name>→ create branchgit checkout <name>→ switch branchgit checkout -b <name>→ create + switchgit merge <branch>→ merge branchgit branch -d <name>→ delete branch
- Be ready to identify scenarios in IT where branching is used (features, bug fixes, releases, hotfixes).
Branches are fundamental to team-based development in Git and a core topic for the DEVASC exam. Understanding them clearly will make you confident in version control tasks.
