Skip to content

Commit 077698f

Browse files
committed
Split out PRs and reorder lesson
1 parent cfb4059 commit 077698f

File tree

2 files changed

+85
-69
lines changed

2 files changed

+85
-69
lines changed

00-programming-fundamentals/managing-git-branches.md

Lines changed: 16 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
11
# Managing Git Branches
2+
23
## Learning Goals
34
- Explore how Git tracks _branches_
45
- Learn common uses of the `checkout` command for managing _branches_
56
- Examine the difference between _merge_ and _rebase_
67
- Discuss when to _branch_, when to _merge_, and when to _rebase_
7-
- Learn about Pull Requests for branches.
88

99
## Branches
1010
Much of this discussion is going to happen on the whiteboard with sticky notes and drawing. However, here's a list of handy Git commands for working with branches:
1111

12-
### File Commands
13-
- `git checkout [path/to/file]`: reverts any unstaged changes to the specified file(s) to their last committed state.
14-
- `git checkout .`: reverts all unstaged changes to tracked files in the current direstory to their last committed state.
15-
- `git stash -k`: set aside unstaged changes into a stash.
16-
- `git stash`: set aside _all_ changes into a stash.
17-
- `git stash pop`: apply the most recently (unapplied) stash.
18-
19-
(Changes that haven't been `add`ed are unstaged.)
20-
21-
### Branch Maintenance Commands
22-
- `git checkout [branch_name]`: switches Git to an _existing_ branch.
23-
- `git branch [branch_name]`: creates a new branch _but does not switch to it_.
24-
- `git checkout -b [branch_name]`: creates a new branch and switches Git to this _new_ branch.
25-
- `git branch -a`: shows a list of all local and remote branches.
26-
- `git branch -d [branch_name]`: delete the specified local branch.
27-
2812
### Branch Sharing Commands
2913

3014
#### Update a Remote Branch (from your local branch)
@@ -94,64 +78,27 @@ $ git merge master
9478

9579
This won't always be possible in practice but it's a good guiding principle and will make your life easier if you can stick to it as much as possible.
9680

97-
### Pull Requests
98-
99-
You've dealt with Pull Requests between forks before, however they are also extremely helpful when using branches as well!
100-
101-
#### Creating a Pull Request
102-
To create a pull request first push your branch to Github: `git push -u origin [branch_name]`.
103-
104-
Then open your repository on Github and click on the "X branches" link near the top.
105-
106-
![A screenshot of Github showing the location of the branch link](images/branch-button.png)
107-
108-
From the branches page locate the branch you are interested in the "Your Branches" section and click "New pull request".
109-
110-
![A screenshot of Github showing the location of the "New pull request" button.](images/new-pr-button.png)
111-
112-
Once you're on the "Open a pull request" page you have one final step. Fill in your title and description and then click "Create pull request". In the sidebar you can add your teammates as reviewers if you'd like so that they receive an email telling them to review the PR.
113-
114-
![A screenshot of Github showing the location of the "Create pull request" button.](images/create-pull-request.png)
115-
116-
#### Reviewing a Pull Request
117-
118-
To start we need to go into the "Files changed" section of the pull request.
119-
120-
![A screenshot showing the files changed link.](images/files-changed-button.png)
121-
122-
To add a comment hover over the margin for the line you would like to comment on and click on the blue plus sign.
123-
124-
![A screenshot showing the comment plus sign button.](images/add-a-comment-button.png)
125-
126-
This will open a box that lets you leave a comment and then begin a code review. Choose "Start a review" and not "Add a single comment".
127-
128-
![A screenshot of the review comment window.](images/add-a-comment.png)
129-
130-
To finish reviewing a Pull Request click on the green "Review changes" button in the upper right corner.
131-
132-
![A screenshot of Github showing the location of the "Review changes" button.](images/review-changes-button.png)
133-
134-
This will open a box giving you space to write a comment and three options:
135-
136-
- Comment: use this when you don't have an opinion on whether or not the PR should be merged.
137-
- Approve: use this when you think the PR should be merged.
138-
- Request changes: use this when you think the PR needs more work before merging.
139-
140-
![A screenshot showing Github's "Review changes" dialog.](images/review-changes-dialog.png)
141-
142-
Click "Submit review" to finish.
81+
### Branch Maintenance Commands
14382

144-
#### Merging a Pull Request
83+
These commands allow you to create, switch and delete branches.
14584

146-
Once a PR has been reviewed click back into the "Conversation" view.
85+
- `git checkout [branch_name]`: switches Git to an _existing_ branch.
86+
- `git branch [branch_name]`: creates a new branch _but does not switch to it_.
87+
- `git checkout -b [branch_name]`: creates a new branch and switches Git to this _new_ branch.
88+
- `git branch -a`: shows a list of all local and remote branches.
89+
- `git branch -d [branch_name]`: delete the specified local branch.
14790

148-
![A screenshot showing the conversation view button for a PR.](images/conversation-button.png)
91+
### File Commands
14992

150-
Scroll down to the bottom until you get to the "Merge pull request" box. Click on "Merge pull request" to merge the PR and then click "Confirm merge".
93+
These commands let you clear out or set aside changes to files.
15194

152-
![A screenshot of the PR merging UI.](images/merge-pull-request.png)
95+
- `git checkout [path/to/file]`: reverts any unstaged changes to the specified file(s) to their last committed state.
96+
- `git checkout .`: reverts all unstaged changes to tracked files in the current direstory to their last committed state.
97+
- `git stash -k`: set aside unstaged changes into a stash.
98+
- `git stash`: set aside _all_ changes into a stash.
99+
- `git stash pop`: apply the most recently (unapplied) stash.
153100

154-
Your PR might say that you aren't ready to merge because there are conflicts with the base branch. In this case you probably need to merge `master` (see [Working with Branches](#working-with-branches)).
101+
(Changes that haven't been `add`ed are unstaged.)
155102

156103
## Resources
157104
- [Git SCM Documentation](https://git-scm.com/book/ch3-2.html)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Using Pull Requests for Branches
2+
3+
## Learning Goals
4+
- Learn how to create a Pull Request from a branch.
5+
- Learn how to review a pull request.
6+
- Learn how to merge a pull request.
7+
8+
## Creating a Pull Request
9+
10+
You've dealt with Pull Requests between forks before, however they are also extremely helpful when using branches as well!
11+
12+
To create a pull request first push your branch to Github: `git push -u origin [branch_name]`.
13+
14+
Then open your repository on Github and click on the "X branches" link near the top.
15+
16+
![A screenshot of Github showing the location of the branch link](images/branch-button.png)
17+
18+
From the branches page locate the branch you are interested in the "Your Branches" section and click "New pull request".
19+
20+
![A screenshot of Github showing the location of the "New pull request" button.](images/new-pr-button.png)
21+
22+
Once you're on the "Open a pull request" page you have one final step. Fill in your title and description and then click "Create pull request". In the sidebar you can add your teammates as reviewers if you'd like so that they receive an email telling them to review the PR.
23+
24+
![A screenshot of Github showing the location of the "Create pull request" button.](images/create-pull-request.png)
25+
26+
## Reviewing a Pull Request
27+
28+
To start we need to go into the "Files changed" section of the pull request.
29+
30+
![A screenshot showing the files changed link.](images/files-changed-button.png)
31+
32+
To add a comment hover over the margin for the line you would like to comment on and click on the blue plus sign.
33+
34+
![A screenshot showing the comment plus sign button.](images/add-a-comment-button.png)
35+
36+
This will open a box that lets you leave a comment and then begin a code review. Choose "Start a review" and not "Add a single comment".
37+
38+
![A screenshot of the review comment window.](images/add-a-comment.png)
39+
40+
To finish reviewing a Pull Request click on the green "Review changes" button in the upper right corner.
41+
42+
![A screenshot of Github showing the location of the "Review changes" button.](images/review-changes-button.png)
43+
44+
This will open a box giving you space to write a comment and three options:
45+
46+
- Comment: use this when you don't have an opinion on whether or not the PR should be merged.
47+
- Approve: use this when you think the PR should be merged.
48+
- Request changes: use this when you think the PR needs more work before merging.
49+
50+
![A screenshot showing Github's "Review changes" dialog.](images/review-changes-dialog.png)
51+
52+
Click "Submit review" to finish.
53+
54+
## Merging a Pull Request
55+
56+
Once a PR has been reviewed click back into the "Conversation" view.
57+
58+
![A screenshot showing the conversation view button for a PR.](images/conversation-button.png)
59+
60+
Scroll down to the bottom until you get to the "Merge pull request" box. Click on "Merge pull request" to merge the PR and then click "Confirm merge".
61+
62+
![A screenshot of the PR merging UI.](images/merge-pull-request.png)
63+
64+
Your PR might say that you aren't ready to merge because there are conflicts with the base branch. In this case you probably need to merge `master` (see [Working with Branches](#working-with-branches)).
65+
66+
## Resources
67+
68+
- [Github: Creating a Pull Request](https://help.github.com/en/articles/creating-a-pull-request)
69+
- [Github: Merging a Pull Request](https://help.github.com/en/articles/merging-a-pull-request)

0 commit comments

Comments
 (0)