Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newfeature/pull requests #25

Merged
merged 10 commits into from
Feb 14, 2025
2 changes: 2 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ website:
- git-refresher/recording-changes.qmd
- git-refresher/syncing-changes-to-remote.qmd
- git-refresher/moving-between-branches.qmd
- git-refresher/making-a-development-branch.qmd
- git-refresher/pull-requests.qmd
- section: "GitHub DevOps basics refresher"
contents:
- github-devops-refresher/navigating-branches.qmd
Expand Down
Binary file added git-refresher/images/dev_branch_GitBash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added git-refresher/images/dev_branch_GitHubDesktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added git-refresher/images/dev_branch_Rstudio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added git-refresher/images/dev_branch_pycharm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added git-refresher/images/pull-request-in-GitHub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added git-refresher/images/pull-request-review.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added git-refresher/images/pull_requests_tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions git-refresher/making-a-development-branch.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "Making a development branch"
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved
---

This section will guide you through how to create a development branch, taking the main branch you created as a base.

When you create a Git project, it will automatically create a "main" (sometimes "master") branch for you. This is where the code that has been QA'd and you are happy with should sit.

It is good practice to have at least one other branch. Having two branches means that if anything goes wrong in the "development branch", the "main" branch is still unaffected and runs without issue. This lets you test and QA the code more thoroughly before merging into your main branch.
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved

::: callout-tip
Chose one method below to create your development branch. Then follow the instructions at the bottom of this page to update your logbook.
:::

::: panel-tabset
## Git Bash

1. Ensure you're on your own personal main branch that you created in [making a branch](#making-a-branch). If you aren't sure use:

``` bash
git checkout -b <github_username>/main
```

2. Pull the latest changes from the remote repository.

``` bash
git pull origin <github_username>/main
```

3. Create your new development branch

``` bash
git checkout -b <github_username>/development
```

4. Push the new branch to the remote repository:

``` bash
git push -u origin <github_username>/development
```

5. Check that the new branch shows in the branch list.

``` bash
git branch
```

![Creating a new branch in GitBash](./images/dev_branch_GitBash.png)

## RStudio

Ensure you are on your personal main branch.

In the Git panel, click the purple new branch symbol ![symbol containing two purple boxes branching from a diamond](images/new-branch_rstudio-button.png) as circled in the screenshot below.

Then enter your development branch name as **`<github_username>/development`** (but replacing <github_id> with your own GitHub username, e.g. `jsmith_development`)

![Creating a new branch in RStudio](./images/dev_branch_RStudio.png)

## GitHub Desktop

Click **Branch** in the menu bar and then select **New branch...** as shown in the screenshot below.

Then enter your branch name as **`<github_username>/development`** (but replacing <github_id> with your own GitHub username, e.g. `jsmith_main`)

![Creating a new branch in GitHub Desktop](./images/dev_branch_GitHubDesktop.png)

## VS Code

The current branch **`(<github_username>main)`** should be listed in the very bottom left hand corner of the VS Code window frame. If you left click on this, you should then see a menu appear at the top of the VS Code window with some branch options (as shown in the screen shot below).

Click **+ Create new branch...** and then enter your branch name as **`<github_username>/development`** (but replacing <github_id> with your own GitHub username, e.g. `jsmith_development`).

You should now see the branch name listed in the bottom left of the window frame shown as the branch you just created, meaning any changes you currently make will be applied to that new development branch (and not the main branch, or your personal main branch).


## PyCharm

Open up the Git panel in PyCharm and you should see something like the screenshot below. Right click on your **`<github_username>/main`** branch and select **New branch from '\<github_id\>/main'...**.

Then enter your branch name as **`<github_username>/development`** (but replacing <github_id> with your own GitHub username, e.g. `jsmith_development`).

![Creating a new branch in PyCharm](./images/dev_branch_PyCharm.png)

:::

::: callout-tip
## Edit your git-academy-log file
Now you have made your development branch, go to your git log and update tick the 'making a development branch' box. Use the [recording changes](recording-changes) section for a reminder on how to make and save changes. Ensure to commit and push your changes.
:::
99 changes: 99 additions & 0 deletions git-refresher/pull-requests.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved
title: "Pull requests"
---

A [pull request](../glossary.html#pull_request) allows you to notify your team about changes you've committed and pushed to a branch in a repository on GitHub. Once a pull request is opened, you can discuss and review the potential changes with collaborators and add any necessary follow-up commits before the changes are merged into the main branch.

Now you have made changes in your [development branch](making-a-development-branch), we will practice this by merging the changes into your main branch using a pull request.

## Creating pull requests

Once you have made all the changes you want to include in this batch of work, you'll bundle all of your commits together into a pull request for review.

::: panel-tabset
## Git Bash

1. Ensure you are on the development branch.

``` bash
git checkout -b <github_username>/development
```

2. Check all your latest changes are pushed to the remote repository.
``` bash
git push origin <github_username>/development
```
3. Create your pull request, adding a title and a description of your changes

``` bash
gh pr create --base <github_id>/main --head <github_id>/development --title "Update to log book" --body "Updating logbook to reflect completing the development branch task."
```

## Rstudio and GitHub Website

1. In the Git panel, ensure you are on the development branch.
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved
2. Check you have pushed your latest changes to the remote repository by clicking the green 'Push' button in the Git window.
3. Go to the [git-academy-sandbox](https://github.com/dfe-analytical-services/git-academy-sandbox) repository page on GitHub.
4. Navigate to the Pull requests tab underneath the repository title.

![](images/pull_requests_tab.png){fig-alt="Higlighting the Pull requests tab on GitHub."}


5. Open a pull request by clicking the "New pull request" button.

6. Ensure the base branch is set to your own main branch (<github_username>/main) and the compare branch is set to your development branch (<github_username>/development).

![](images/pull_request_branch_selection.png){fig-alt="Higlighting where to change the base and compare branches once you have pressed the 'create a pull request' button on GitHub."}


7. Create Pull Request: Click the "Create pull request" button. Add a title and description for your pull request. You may wish to explain what changes and been made, and why.

8. You don't need to add any reviewers in this training, but please do take a moment to notice where you can add team mates to review your pull requests in your own work to the right of the description. Any reviewers you add will be notified by email that there is a pull request for them to review.

9. Once you are happy with your title and description, click 'Create pull request' to confirm.

10. You will then want to check whether there are any merge conflicts. If there are merge conflicts, they will need resolving before you are able to complete your pull request.

## GitHub Desktop

1. Ensure you are on the development branch.

2. Click on the 'Branch' menu and 'Create pull request'

3. Click 'open in browser'. This will open GitHub in your web browser with the pull request form pre-filled.

4. Add a title and description for you pull request and then click 'Create pull request'

## VS Code

## PyCharm
:::

## Reviewing pull requests
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved

When a pull request is created, it's important to review the changes carefully. This process helps ensure that the code meets the project's standards and doesn't introduce any new issues. During the review, you can discuss the changes with the author, suggest improvements, and request additional commits if necessary.

We will practice this by reviewing the pull request you have just made.

### GitHub Website

1. Go back to the [git-academy-sandbox](https://github.com/dfe-analytical-services/git-academy-sandbox) repository overview page on GitHub, as if you have just come to find the pull request your colleague has asked you to review.

2. Navigate to the 'Pull requests' tab.

3. Click on the pull request you want to review, in this case the one you created above.

![](images/pull-request-in-GitHub.png){fig-alt="Higlighting where open pull requests show in GitHub once the Pull request tab has been opened."}

4. Review the changes by looking at the "Files changed" tab. You can see a side-by-side comparison of the changes made.Add comments by clicking the "+" icon next to the lines of code you want to comment on.
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved

![](images/pull-request-files-changed.png){fig-alt="Higlighting where to view comparison of changes made and make comments on a pull request."}

5. When reviewing pull requests, you may also wish to view changes locally to check the code runs and view any outputs.You can do this by pulling and changing to the branch that is being requested to be merged in.
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved

6. Once you have reviewed the changes, you can leave general feedback, approve or request changes by clicking the 'review changes' button.

![](images/pull-request-review.png){fig-alt="Higlighting where to provide general feedback, request changes or approve on a pull request."}

7. Once you are happy with the changes, you should approve the pull request. The person who created the request will then get an email letting them know their changes have been approved and can go back and complete the request.
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved

13 changes: 11 additions & 2 deletions git-refresher/recording-changes.qmd
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: "Recording changes (add and commit)"
title: "Recording changes (add, commit and push)"
---

This section will guide you through recording changes you make to your repo through the process of [**adding**](../glossary.html#add) and [**staging**](../glossary.html#stage) files.
This section will guide you through recording changes you make to your repo through the process of [**adding**](../glossary.html#add), [**staging**](../glossary.html#stage) and [**pushing**](../glossary.html#push) files.

These steps help you manage and track changes in your project, making collaboration and version control efficient and reliable.

Expand Down Expand Up @@ -38,6 +38,10 @@ Having [created your own branch](making-a-branch.html), follow the instructions
- Commit changes with a message by entering:

`git commit -m "Checked clone sandbox and make new branch tasks"`

- Push the changes to the remote repository
`git push origin <github_username>/main`


## RStudio

Expand All @@ -54,6 +58,8 @@ Having [created your own branch](making-a-branch.html), follow the instructions

Note that you can see the changes made by comparing the green (current version) and the red (old version) highlighted sections.

- Then either push up your changes to the remote directly from the commit box using the green 'push' upwards arrow in the top right corner, or close the box and push using the 'push' green arrow in the Git window.

## GitHub Desktop

## VS Code
Expand All @@ -75,4 +81,7 @@ OR
- Click "Commit".

![](images/pycharm_commit_msg.png){fig-alt="Highlighting the commit message section and the Commit button in the Commit pop up window that appears after completeing the last step."}

- Push the committed changes to the remote repository by clicking the "Push" button in the top-right corner of the PyCharm window.

:::
14 changes: 13 additions & 1 deletion glossary.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ Committing is where you record changes in the Git history. This is one of the mo

Cloning a repository is the process of creating a copy of a repository folder system on your local working environment (e.g. your laptop computer).

## Pull

Pulling updates your current local working branch with any changes from the remote branch. You should pull every day that you interact with a repository, at the minimum.
Lsnaathorst1 marked this conversation as resolved.
Show resolved Hide resolved

## Pull request

A pull request is a method used in Git to propose changes to a branch. It allows collaborators to review and discuss changes before merging into the main branch.

## Push

Pushing is the process of updating the remote branch with local commits.

## Repository

A repository (or repo) is effectively a project folder. A given repostory would usually contain all the work for a specific project (e.g. a data pipeline, an R-Shiny app, etc).
A repository (or repo) is effectively a project folder. A given repository would usually contain all the work for a specific project (e.g. a data pipeline, an R-Shiny app, etc).

## Stage

Expand Down