Skip to content

Commit cb9c185

Browse files
committed
Added github flow exercise
1 parent 54333ae commit cb9c185

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# GitHub flow
2+
3+
The [GitHub flow](https://docs.github.com/en/get-started/quickstart/github-flow) is a lightweight, [branch-based](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches) workflow. It's designed to allow for free testing and exploration of ideas and novel approaches which are then reviewed and, if accepted, brought into the codebase. At a high level, the GitHub flow follows this pattern:
4+
5+
1. Create a branch
6+
1. Make the desired changes
7+
1. Create a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests)
8+
1. Review changes, gather feedback and make updates
9+
1. Review results of automated operations such as testing for continuous integration
10+
1. If changes are approved, merge into codebase
11+
12+
The GitHub flow is designed to work as a cycle, where contributors continuously explore, test, review, and build upon their work and the work of others.
13+
14+
> **NOTE:** One key philosophy for GitHub flow is not every pull request needs to be merged. Sometimes exploration is the goal, the feature isn't one which is desired by the greater team, or wholesale changes need to be made necessitating starting over. This is part of the process, and allows for free experimentation.
15+
16+
## Scenario
17+
18+
With the code changes created in the [prior exercise](./5-coding.md), it's time to walk through the GitHub flow to create a pull request and incorporate the updates into the codebase. While the changes have already been made (meaning we are slightly out of order from the "traditional" flow), you can still perform the steps to explore.
19+
20+
## Creating a branch
21+
22+
A [branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-branches) is a copy of the code stored in the same repository. By using branches to test updates you have a safe space to explore while keeping all code in the same repository.
23+
24+
There are different ways to create a branch when using [GitHub Codespaces](https://github.com/features/codespaces). You can utilize the command-line to run [git](https://git-scm.com/docs/git-branch) commands. You can use the Source Control pane in your codespace to get the support of the UI for creating your branch. In our example we're going to use the command-line to create the branch.
25+
26+
1. Return to your codespace, or reopen it by navigating to your repository and selecting **Code** > **Codespaces** and the name of your codespace.
27+
1. Open a **terminal window** by pressing <kbd>Ctl</kbd> + <kbd>`</kbd>.
28+
1. In the terminal window, enter the following command to create and switch to a new branch named `add-hours` and pressing <kbd>Enter</kbd> (or <kbd>Return</kbd> on a Mac)::
29+
30+
```bash
31+
git checkout -b add-hours
32+
```
33+
34+
1. Stage all code to be committed to the new branch by entering the following command in the terminal window and pressing <kbd>Enter</kbd> (or <kbd>Return</kbd> on a Mac):
35+
36+
```bash
37+
git add .
38+
```
39+
40+
1. Commit all changes with a message describing what's been updated by entering the following command in the terminal window and pressing <kbd>Enter</kbd> (or <kbd>Return</kbd> on a Mac):
41+
42+
```bash
43+
git commit -m "Added hours component"
44+
```
45+
46+
1. Finally, push the new branch to the repository by entering the following command in the terminal window and pressing <kbd>Enter</kbd> (or <kbd>Return</kbd> on a Mac):
47+
48+
```bash
49+
git push -u origin add-hours
50+
```
51+
52+
## Create the pull request
53+
54+
A [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) is a request to pull or incorporate new code into the existing codebase. When a pull request is made it's customary to have other team members review the code and make comments, and for [CI/CD](https://resources.github.com/ci-cd/) processes to run. Once everything is completed and the code is in a stage where everyone has signed-off, it's then merged into the codebase.
55+
56+
Pull requests can be made through the source control pane in the codespace, the repository's website, or through the command-line using the [GitHub CLI](https://cli.github.com/). In our example we're going to create the pull request in the CLI, then navigate to the website to see the pull request and the actions running, and merge the code into the codebase.
57+
58+
1. Return to your codespace.
59+
1. Find the number for the [issue you created earlier](./2-issues.md) titled **Add component to display hours** by entering the following command in the terminal window and pressing <kbd>Enter</kbd> (or <kbd>Return</kbd> on a Mac):
60+
61+
```bash
62+
gh issue list
63+
```
64+
65+
1. Create a pull request with the title **Add hours component** and body **Resolves #\<ISSUE_NUMBER\>**, replacing **\<ISSUE_NUMBER\>** with the issue number you obtained in the previous step by entering the following command in the terminal window and pressing <kbd>Enter</kbd> (or <kbd>Return</kbd> on a Mac):
66+
67+
```bash
68+
gh pr create -t "Add hours component" -b "Resolves #<ISSUE_NUMBER>"
69+
```
70+
71+
## Merge the pull request
72+
73+
When the pull request is created, you will see a link appear to the page for the pull request. From there you can add comments, see any workflows running, and decide to close or merge the pull request. Let's ensure the tests now run successfully and, assuming they do, merge the pull request.
74+
75+
1. Follow the link displayed in the terminal window by using <kbd>Ctl</kbd> - **Click** (or <kbd>Cmd</kbd> - **Click** on a Mac).
76+
1. In the page displayed, note the workflow running the [end-to-end tests created earlier](./4-testing.md).
77+
1. When the test passes successfully, select **Merge pull request** to merge your changes into the **main** branch.
78+
79+
Congratulations! You've now used the GitHub flow to suggest changes, perform a review, and merge those into your codebase.
80+
81+
## Summary and next steps
82+
83+
The GitHub flow is a workflow for managing changes and incorporating new features into a codebase. GitHub flow gives you the freedom to explore and experiment, while ensuring all code follows a validation process before being merged. With the code updated, it's time to deploy the project! The first step is to [create the deployment environment](./7-create-environment.md).
84+
85+
## Resources

0 commit comments

Comments
 (0)