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

Navigating branches and syncing #18

Open
wants to merge 11 commits into
base: newcontent/basics-refresher
Choose a base branch
from
Open
Binary file added git-refresher/images/pycharm_commit.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/pycharm_commit_msg.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/pycharm_groupby_prefix.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/pycharm_push1_1.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/pycharm_push1_2.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/pycharm_push2.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/pycharm_switch_main.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/r_commit.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/r_commit_msg.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/r_push_1.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/r_push_2.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/r_switch_branch_main.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.
10 changes: 5 additions & 5 deletions git-refresher/making-a-branch.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Replace `<github_id>` in the below with your GitHub username to make your own
personal main branch in the sandbox repository.

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

## 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_id>_main`** (but replacing <github_id>
Then enter your branch name as **`<github_username>/main`** (but replacing <github_id>
with your own GitHub username, e.g. `jsmith_main`)

![Creating a new branch in GitHub Desktop](./images/new-branch_GitHubDesktop.png)
Expand All @@ -42,7 +42,7 @@ 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_id>_main`** (but replacing <github_id> with your own GitHub username,
**`<github_username>/main`** (but replacing <github_id> with your own GitHub username,
e.g. `jsmith_main`).

You should now see the branch name listed in the bottom left of the window frame
Expand All @@ -57,7 +57,7 @@ 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 branch name as **`<github_id>_main`** (but replacing <github_id>
Then enter your branch name as **`<github_username>/main`** (but replacing <github_id>
with your own GitHub username, e.g. `jsmith_main`)

![Creating a new branch in RStudio](./images/new-branch_RStudio.png)
Expand All @@ -69,7 +69,7 @@ Open up the Git panel in PyCharm and you should see something like the
screenshot below. Right click on **main** and select
**New branch from 'origin/main'...**.

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

![Creating a new branch in PyCharm](./images/new-branch_PyCharm.png)
Expand Down
78 changes: 76 additions & 2 deletions git-refresher/moving-between-branches.qmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,92 @@
---
---
title: "Moving between branches"
---

...
Now that you've made and [recorded some changes](recording-changes.html) on your working branch and [synced them to the remote repo](syncing-changes-to-remote.html), we can look at how to move between branches and what that looks like in terms of file changes.

Switching branches is useful for when we might need to pause our work on one branch and continue working on an issue in another branch. Before you switch branches it is important to commit the changes you made in the branch you're currently in. It's also important to pull changes after you switch to your new branch.

::: panel-tabset
## Git Bash

First you need to update your local repo with the changes made to the remote one. This ensures that you have a full list of remote branches and the latest changes in the code to avoid conflicts.

- Enter the command below to update your local repo:

`git pull`

- Switch to the main branch by using this command:

`git checkout main`

- Check the "git-academy-log.md" file and you'll see your edits have disappeared.

- Switch back to your branch by using this command:

`git checkout <github_username>/main`

- Check the "git-academy-log.md" file and you'll see your edits have returned.

### Alternative method

You can also use the `git switch` command interchangeably with the git checkout command for switching branches.

## GitHub Desktop

## VS Code

## RStudio

- Go to the right hand side of RStudio and click on the Git tab.

- Click on the downwards arrow to "pull" the latest changes from the remote repo. This ensures that:

- you have a full list of remote branches.
- you have the latest changes in the code to avoid conflicts.

- Click on the drop down menu of branches.

- Click on `main`

![](images/r_switch_branch_main.png){fig-alt="The Git panel in RStudio with red rectangles highlighting the downwards pull arrow, the branches drop down menu and the branch called main that we want to switch to."}

- Check the "git-academy-log.md" file and you'll see your edits have disappeared.

- Click on the drop down menu of branches.

- Click on `<github_username>/main`

![](images/r_switch_branch_own_branch.png){fig-alt="The Git panel in RStudio with red rectangles highlighting the branches drop down menu and an example of a user branch that we want to switch to."}

- Check the "git-academy-log.md" file and you'll see your edits have returned.



## PyCharm

- Click on the branches drop down menu at the top of the screen.

- Click the Fetch icon to "pull" the latest changes from the remote repo. This ensures that:

- you have a full list of remote branches.
- you have the latest changes in the code to avoid conflicts.

- Click on "Remote" to see the full list of remote branches if you can't already.

- Click on `main`and then click "Checkout".

![](images/pycharm_switch_main.png){fig-alt="Highlighting PyCharm's branches dropdown menu, the Remote drop down sub menu, the branch called main and the Checkout option that appears when you click on that branch."}

- Check the "git-academy-log.md" file and you'll see your edits have disappeared.

![](images/pycharm_switch_own_branch.png){fig-alt="Highlighting PyCharm's branches dropdown menu, the Remote drop down sub menu, an example of a user specific branch and the Checkout option that appears when you click on that branch."}

- Click on the branches drop down menu at the top of the screen.

- Click on `<github_username>/main` and then click "Checkout".

- Check the "git-academy-log.md" file and you'll see your edits have returned.



:::
64 changes: 62 additions & 2 deletions git-refresher/recording-changes.qmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,78 @@
---
---
title: "Recording changes"
---

...
This section will guide you through recording changes you make to your repo.

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

Having [created your own branch](making-a-branch.html), follow the instructions below to make and record changes in your repo.

::: callout-tip
## Edit your git-academy-log file

- Put an x inside the brackets for the "Clone git-academy-sandbox" and "Create a new branch in GitHub (\<github_username\>/main)".

- Save the file.
:::

::: panel-tabset
## Git Bash

- Check which files have changed by entering this command in Git Bash:

`git status`

- Stage the changes you want to commit by using one of the commands below.

- To add changes to one file at a time:

`git add git-academy-log.md`

OR

- To add all changes:

`git add .`

- Commit changes with a message by entering:

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

## GitHub Desktop

## VS Code

## RStudio

- In the Git panel of RStudio (see image below), tick the files you want to record the changes for.
- Click the commit button. It has a tick mark on two sheets of paper.

![](images/r_commit.png){fig-alt="Higlighting the Commit button and an example of ticking changes in the Git panel in RStudio."}

- Write a short message to describe the changes you made.

- Click "Commit".

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

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

## PyCharm

- Click on the branches drop down menu at the top of the screen and click "Commit".

OR

- Click on the symbol that shows a circle flanked by two lines in the sidebar as shown in the image below.

![](images/pycharm_commit.png){fig-alt="Highlighting the two ways to open the commit window." width="461"}

- In the "Commit" pop up window, tick the files you wish to record changes for if they're not already ticked.

- Write a short message to describe the changes you made.

- 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."}
:::
41 changes: 39 additions & 2 deletions git-refresher/syncing-changes-to-remote.qmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,55 @@
---
---
title: "Syncing to the remote"
---

...
This section will guide you through syncing your local repo to the remote one.

Any change made so far is only being applied to the local copy of the repository (i.e. the copy on your laptop). To apply your changes to the remote repository (i.e. on GitHub or Azure DevOps), you need to “push” the changes.

Having [recorded your changes](recording-changes.html), follow the instructions below to sync to the remote.

::: panel-tabset
## Git Bash

The first time you update your remote repo with the changes you committed to your local one (aka push the changes), use the command below:

`git push --set-upstream origin <github_username>/main`

After that, if you want to push changes you committed in the same branch use the following command:

`git push`

## GitHub Desktop

## VS Code

## RStudio

Click the green upwards arrow to push your changes to the remote repo. You can do this from the commit window as shown in the image below.

![](images/r_push_1.png){fig-alt="Highlighting the upwards arrow for pushing changes to remote repos in the RStudio's Review Changes window."}

### Alternative method

You can also do this from the side panel after closing the commit window as shown in the image below.

![](images/r_push_2.png){fig-alt="Highlighting the upwards arrow for pushing changes to remote repos in RStudio's Git window. It is there to show an alternative way of pushing changes to remote repos."}

## PyCharm

- Click on the branches drop down menu at the top of the screen and click "Push".

- A screen will pop up with your previous committed changes.

- Click "Push".

![](images/pycharm_push1_1.png){fig-alt="Highlighting the Push option in the branch drop down menu."}

![](images/pycharm_push1_2.png){fig-alt="Highlighting the Push button in the Push Commits to git-academy-sandbox pop up window that appears after completeing the previous step."}

### Alternative method

Alternatively you can push and commit your changes at the same time from the commit window by clicking "Commit and Push" after you write your commit message.

![](images/pycharm_push2.png){fig-alt="Highlighting the Commit and Push button in the Commit pop up window that appears after following the steps in recoding changes part of this guide."}
:::
Loading