GitHub Flow - Part 2
GitHub Flow - Part 2
In our last session, we set up our workspace by forking and cloning the First Contributions repository and configured the upstream remote to stay synchronized with the original project. As we continue our GitHub Flow journey, we will focus on creating a new branch and effectively working on your feature.
Creating a New Branch
Branches are integral in GitHub Flow. Creating a branch means duplicating the project at its current state to work independently without affecting the main branch. The main branch should always reflect a deployable state of your project.
How to Create a New Branch
Creating a new branch is simple. Navigate to your project’s directory and run the following command, replacing
feature-name with a descriptive name for your branch:
git checkout -b feature-namebash
Naming Conventions for Branches
Naming your branch appropriately can convey its purpose clearly. Here are some tips for naming your branches:
- Use hyphens to separate words.
- Be succinct and descriptive.
- Prefix the branch name with categories like
chore/to indicate the kind of work involved.
Working on Your Feature
Making Changes Locally
Open the project in your favorite text editor and start making changes. Use the
git status command regularly to keep track of the modified files.
Best Practices for Committing Your Changes
Before you commit your changes, adhere to the following practices:
- Craft clear and descriptive commit messages.
- Make atomic commits, which refer to small, self-contained changes.
- Ensure to test your changes locally to confirm everything works as expected.
Commit your changes with this command:
git commit -m "Your descriptive commit message here"bash
Pushing Changes to Your GitHub Repository
After committing your changes locally, push them to your GitHub repository with this command:
git push origin feature-namebash
Great job! You've now successfully created a new branch and worked on your feature using GitHub Flow. In our next article, we will cover how to open a pull request and collaborate with other developers to merge your changes into the main branch. Stay tuned and happy coding!
Thanks for reading. If you enjoyed this post, I invite you to explore more of my site. I write about web development, programming, and other fun stuff.