Skip to content
Corbin Brown
0:12:35
51
4
1
Last update : 19/04/2025

Mastering GitHub Branches and Pull Requests 🚀

Table of Contents

GitHub branches and pull requests (PRs) are the backbone of collaborative coding in the modern software development process. Whether you’re working solo or with a team, understanding how to create branches, manage commits, and merge changes can drastically improve your workflow. This guide simplifies these concepts so you can start applying them today! 🌟


📚 Why GitHub Branches Matter

GitHub branches allow developers to make changes to a copy of the main codebase without affecting production (live) code. Just like checkpoints in a video game, branches ensure that you can experiment, iterate, and even backtrack without breaking the main application.

Key Insights:

  • The main branch represents tested code in production (live environment), ensuring visitors to your website or app experience stable functionality.
  • Separate branches empower you to test new features or fixes without risking disruptions to live users.

Real-Life Example:

Imagine you’re creating a web app and need to tweak the footer. By creating a branch named “footer-change,” you can test updates without altering the live website.

Practical Tip:

Always branch out from main whenever you start working on a new feature. Use descriptive branch names to make intentions clear (like feature/login-page or bugfix/header-responsive).


🛠️ Creating and Managing Branches

Creating a branch is simple, and tools like Visual Studio Code (VS Code) streamline the process. Here’s how you can do it!

Steps:

  1. Navigate to Your Project Directory:
    Use cd [your-folder-name] in the terminal to get into your project’s folder.

  2. Check Your Current Branch:
    Run git branch to see active branches. The starred branch (e.g., * main) indicates the branch you’re working on.

  3. Create and Switch to a New Branch:
    Use git checkout -b <branch-name>. For example:

   git checkout -b footer-change

This creates and switches to the “footer-change” branch.

  1. Start Coding! Add your desired changes to your code.

Real-Life Example:

Say you’re editing the footer to display updated social link icons. Work on these changes in the “footer-change” branch. Once happy, test your updates locally with npm start or the equivalent command.

Practical Tip:

Before switching branches, ensure there are no uncommitted changes in your working tree. Run git status to verify.


📝 Making Commits That Make Sense

Commits serve as snapshots of your project at various stages. This is where your “checkpoint mentality” comes into play – save frequently and descriptively!

Best Practices for Commits:

  1. Commit Locally First: Use git add . to stage files and git commit -m "<commit-message>" to save a snapshot.
    Example:
   git add .
   git commit -m "Updated footer with new social icons"
  1. Make Descriptive Messages: Treat your commit message like a diary entry! Include the what and why. For example:
  • ✅ Good: “Removed inline styles in footer for better readability”
  • ❌ Bad: “Fix”
  1. Push Your Changes: Once satisfied, push your branch changes to the cloud:
   git push origin <branch-name>

Real-Life Example:

You’re working on a project and radically redesign the footer layout. Commit this as:

git commit -m "Revamped footer by removing columns and adding responsive design"

Practical Tip:

If you’re new to Git commands, keep a sticky note with commonly used ones (e.g., git add ., git commit -m, and git push).


🌟 The Power of a Pull Request (PR)

Once you’ve pushed updates to your branch, the next step is to create a pull request on GitHub to merge those changes into the main branch. A PR allows you (or your team) to review, discuss, and test updates before merging them.

How to Submit a PR:

  1. Push your branch to GitHub (e.g., git push origin footer-change).
  2. Visit your GitHub repository and look for a banner/button labeled “Compare and pull request.”
  3. Provide a clear PR description, explaining what changes were made and why.
  4. Submit the PR for review.

Example Workflow:

  • Branch Name: footer-change
  • PR Title:Responsive update for footer layout
  • Description:Replaced footer’s column layout with a single flexbox wrapper for better responsiveness across devices.

Practical Tip:

Before merging, test your branch thoroughly by working locally using npm start. Catching issues at this stage saves time later!


🔄 Rolling Back with Confidence

Made a mistake? Need to revert a change? Fear not – GitHub’s version control lets you roll back to earlier commits effortlessly.

Rolling Back Steps:

  1. Find the Checkpoint Commit: On GitHub, open your PR, go to “Commits,” and copy the SHA (string of numbers/letters) for the commit you want to reset to.

  2. Hard Reset: In your terminal, run:

   git reset --hard <commit-SHA>
  1. Force Update the Cloud: If you’ve pushed earlier buggy updates to GitHub, fix it with:
   git push --force origin <branch-name>

Real-Life Example:

While experimenting, you accidentally butcher the footer. Roll back to the last good commit, fix your mistakes, and try again!

Practical Tip:

Think of git reset --hard as an undo button for your repo. Use it wisely to avoid unnecessary stress when something goes wrong.


🏁 Merging Branches and Clean-Up

Once you’ve validated your work and others have approved your PR, it’s time to merge your branch into main. Here’s how:

Steps:

  1. Merge the PR: In GitHub, open the PR and click “Merge pull request.”
  2. Clean Up: Delete your branch after merging.
    Don’t worry, branches can be restored later if needed.

Real-Life Example:

Your update (from “footer-change”) is merged into main. Upon merging, the live website’s footer reflects these changes.

To confirm success:

  1. Navigate to the GitHub repo.
  2. Switch to the main branch, check files, and verify your changes.

Practical Tip:

Keep your branch-names tidy and delete unused ones post-merge. A chaotic branch list is a productivity killer 🗃️.


💡 Key Takeaways

GitHub branches are essential for:

  • Safely experimenting without risking production code.
  • Collaborating in teams and avoiding merge conflicts.
  • Rolling back to stable commits when things go south.

Keep these practices in mind:

  • Use clear, descriptive branch names and commit messages.
  • Push your changes frequently and test before merging.
  • Merge only after thorough testing.

🧰 Resource Toolbox for Further Learning

Here are some resources to deepen your knowledge:

  1. How to Connect GitHub to an IDE (Video, 28 Mins):
    Boost your setup by linking GitHub to tools like VS Code.
    Watch here

  2. Web App Development with AI (3-Hour Playlist):
    Learn hands-on via a fully documented series!
    Explore the playlist

  3. Ask Me Anything (Premium Lessons):
    Go deeper into GitHub and coding practices!
    Get access here

  4. Chat with Videos Using AI (via BumpUps):
    Interact with video content dynamically!
    Try it now

  5. My Equipment for Productivity:
    Discover tools to streamline development.
    Setup shop


🚀 Final Thought: Code Like a Pro

GitHub branches and PR workflows encourage clean, scalable, and reversible coding practices. Think of repositories as a playground and branches as safety nets for experimentation. Commit often and frequently—just like saving your progress in a favorite video game. Remember: great coding is a balance of risk-taking and methodical organization! Happy coding. 🎉

Other videos of

Play Video
Corbin Brown
0:09:13
122
16
1
Last update : 18/04/2025
Play Video
Corbin Brown
0:06:05
94
9
1
Last update : 17/04/2025
Play Video
Corbin Brown
0:09:40
73
7
0
Last update : 13/04/2025
Play Video
Corbin Brown
0:05:57
98
8
1
Last update : 12/04/2025
Play Video
Corbin Brown
0:53:57
42
3
0
Last update : 12/04/2025
Play Video
Corbin Brown
0:05:32
85
5
0
Last update : 07/04/2025
Play Video
Corbin Brown
0:06:42
78
8
0
Last update : 05/04/2025
Play Video
Corbin Brown
0:07:32
168
10
2
Last update : 04/04/2025
Play Video
Corbin Brown
0:19:16
136
16
2
Last update : 02/04/2025