Branching and Merging with Git from the Command Line
Extend your Git basics by working with branches: create, switch, merge, resolve conflicts, and follow a clean feature-branch workflow.
Branching and Merging with Git from the Command Line is a free Linux Command Line Mastery lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Linux Command Line Mastery learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Branches?
You know how to commit and track files. Branches let you develop features in isolation without disturbing the main line of work, then merge them back when ready.
Listing Branches
git branch lists branches and marks the current one with an asterisk.
git branchCreating and Switching
git switch -c name creates a branch and moves to it in one step. (Older Git uses git checkout -b.)
git switch -c feature-loginCommitting on a Branch
Commits you make now belong only to the feature branch, leaving main untouched.
git add .
git commit -m 'Add login form'Switching Back
Return to main with git switch main. Your feature work is safely stored on its own branch.
git switch mainMerging a Branch
From main, git merge brings the feature commits in. A fast-forward happens when main has no new commits.
git merge feature-loginHandling Merge Conflicts
If the same lines changed on both branches, Git pauses and marks conflicts with <<<<<<< markers. Edit the file to resolve, then stage and commit.
git add resolved-file.txt
git commitDeleting Merged Branches
After merging, clean up with git branch -d. Git refuses if the branch is not merged, protecting your work.
git branch -d feature-loginComparing Branches
git diff between branches shows exactly what differs before you merge.
git diff main..feature-loginPushing a Branch
Share a branch by pushing it and setting upstream tracking with -u.
git push -u origin feature-loginA Clean Workflow
The feature-branch loop: branch from main, commit, push, open a pull request, merge, delete the branch. This keeps history organized and reviewable.
Quick Check
Which single command both creates a new branch and switches to it?
Recap
You can now manage parallel work:
git switch -ccreates and moves to a branchgit mergeintegrates; conflicts are resolved by editing then committinggit branch -dcleans up merged branchesgit push -u originshares them
Branch per feature, merge when done.
Frequently asked questions
Is the “Branching and Merging with Git from the Command Line” lesson free?
Yes — the full text of “Branching and Merging with Git from the Command Line” is free to read here on the web, and the Linux Command Line Mastery course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Linux Command Line Mastery course, upgrade to CoddyKit PRO.
What will I learn in “Branching and Merging with Git from the Command Line”?
Extend your Git basics by working with branches: create, switch, merge, resolve conflicts, and follow a clean feature-branch workflow. You practise Linux Command Line Mastery with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Linux Command Line Mastery?
No prior experience is required. Linux Command Line Mastery on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Branching and Merging with Git from the Command Line” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Linux Command Line Mastery lesson?
Yes. Every Linux Command Line Mastery lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Git Basics from the Command Line
- Environment Variables and Aliases
- Shell Configuration: `.bashrc`, `.zshrc`, `.profile`
- Branching and Merging with Git from the Command Line