AI Hints
Home›Git & GitHub Tutorial›Fixing Conflicts
Git & GitHub · Lesson 50 of 144

Practice: Branches

A feature from start to finish.

⏱ 2 min read▶ Video at 53:34🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

Your turn. Pause the video, and try this. In a repository, create a branch called footer. Add a file called footer dot HTML, and commit it. Switch back to main, merge footer into it, and delete the branch.

Practice: Branches
From the video: Practice: Branches
  • Create a branch: footer
  • Commit footer.html
  • Merge into main, delete the branch

One solution

Here's one solution. Switch dash c footer. Write the file, add it, and commit. Switch back to main. Merge footer, which is a fast forward. And delete the branch with dash d. The graph shows a simple, straight history.

git
git switch -c footer
Switched to a new branch 'footer'
echo '<footer>Made by Sam</footer>' > footer.html
git add footer.html
git commit -m "Add footer"
[footer 1f4ca36] Add footer
 1 file changed, 1 insertion(+)
 create mode 100644 footer.html
git switch main
Switched to branch 'main'
git merge footer
Updating f63a17a..1f4ca36
Fast-forward
 footer.html | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 footer.html
git branch -d footer
Deleted branch footer (was 1f4ca36).
git log --oneline --graph -n 3
* 1f4ca36 (HEAD -> main) Add footer
* f63a17a Link to about page
* ef9c947 Add basic styles

Quick check

Quick check. You run git merge, and Git reports a conflict. What must you do before committing? Delete the branch, remove the conflict markers and git add the file, or run git reset? The answer is remove the markers, and git add the file. Then you can commit.

Quick check
A merge has a conflict. What must you do before committing?

Summary

You can now branch, merge, and fix conflicts. That's the heart of working with Git. Next, comparing branches before you merge.

Key takeaways
  • switch -c, commit, merge
  • Fix conflicts calmly
  • Delete merged branches
Next up: Comparing Branches — what is on each branch?