GitHub Flow
The GitHub Flow is an industry-standard workflow for continuous delivery and collaboration. It’s lightweight, branch-based, and supports teams of any size working on projects of any complexity.
Step 1: Fork a repository
If you want to contribute to a repository where you haven’t been added as a collaborator you need to fork it.
Navigate to the repository on GitHub, e.g. https://github.com/Bristol-Training/demo-calc-lib.
Click “Fork” in the top-right corner This creates a copy under your GitHub account (https://github.com/YOUR-USERNAME/demo-calc-lib)
Step 1: Clone the repository URL
On your repository page in GitHub, click the green “Code” button and copy the HTTPS URL (it should look like https://github.com/YOUR-USERNAME/demo-calc-lib.git).
git clone https://github.com/YOUR-USERNAME/demo-calc-lib.git
cd demo-calc-libStep 2: Pull Latest from Main Branch
Before starting new work, ensure you have the latest version of the main branch. This ensures you’re building on the most recent stable version, reducing the chance of conflicts later.
git checkout main
git pull origin mainStep 3: Create a Feature Branch
Create a new branch for your feature or fix:
git checkout -b feature/add-power-functionBranch naming conventions help teams stay organised:
feature/— for new features (e.g.,feature/add-power-function)fix/orbugfix/— for bug fixes (e.g.,fix/correct-calculation-error)docs/— for documentation updates (e.g.,docs/update-readme)refactor/— for code improvements (e.g.,refactor/simplify-database-queries)
Use descriptive names that explain what the branch does. Avoid vague names like my-branch or updates.
Step 4: Make Commits on Your Branch
Work on your changes and commit regularly:
# Make changes to files
git add .
git commit -m "Add login form component"
# Make more changes
git add .
git commit -m "Add authentication validation logic"Good commit practices:
- Commit small, logical chunks of work
- Write clear, descriptive commit messages
- Use present tense (“Add feature” not “Added feature”)
- Explain what and why, not how
Step 5: Push Branch and Open Pull Request
Push your branch to GitHub:
git push origin feature/add-power-functionThen, on GitHub:
- Navigate to your repository
- Click “Compare & pull request” (appears after pushing)
- Write a clear title and description
- Request reviewers
- Click “Create pull request”
Step 6: Discuss and Review Code
This is where collaboration happens:
- Reviewers examine the code, suggest improvements, and ask questions
- Author responds to comments and makes requested changes
- Discussion happens directly on the Pull Request
To make changes based on feedback:
# Still on your feature branch
# Make the requested changes
git add .
git commit -m "Address review comments: improve error handling"
git push origin feature/add-power-functionThe Pull Request automatically updates with your new commits.
Step 7: Merge to Main and Delete Branch
Once approved, merge the Pull Request via GitHub’s interface:
- Click “Merge pull request”
- Confirm the merge
- Delete the branch (GitHub prompts you to do this)
Then, locally:
git checkout main
git pull origin main
git branch -d feature/add-power-function