Skip to content

Commit

Permalink
Merge branch 'main' into newcontent/basics-refresher
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbielby committed Nov 21, 2024
2 parents da08873 + 978e9d5 commit 855c05e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions ch2-git-basics/cloning.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: "Cloning an Existing Repository"
---

---
## Introduction

This section will guide you through the process of cloning a GitHub repository (repo). A repo contains all of your code, your files and each file's version history. Repos can have multiple collaborators and can be either private or public. You can find out more about GitHub repos on [GitHub Docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/about-repositories).

If you have a repo on Azure DevOps, GitHub or GitLab, you generally can't edit or run your work on those platforms, so if you need to work with the contents of a repo, you'll usually need to make a clone.

There are several ways to clone an existing repo. Below, you'll find two methods. The first uses Rstudio and the second uses Git Bash. Start with step 1, which is the same for both methods, and then decide which method to follow. Once you have successfully cloned, you should see the files appear in the location you have chosen to store your repo.

## Step 1: Get the repository clone link

a\. Go to the [git-academy-sandbox](https://github.com/dfe-analytical-services/git-academy-sandbox) repository page on GitHub.

b\. Click the "Code" button and copy the URL (HTTPS link).

::: panel-tabset
## To Clone Using Git Bash:

### Step 2a: Open folder and Git Bash

Navigate to the folder on your device where you want to clone the repo. Right-click in the directory and select "Git Bash Here".

![](images/gitbash_here.png){width="343"}

### Step 2b: Clone the Repository in Git Bash

- In the Git Bash window that opens, use the \`git clone\` command followed by the URL you copied from GitHub. For this repo, we would enter:

``` bash
git clone https://github.com/dfe-analytical-services/git-academy-sandbox.git
```

You will need to right-click to paste, as the keyboard shortcut will not work in Git Bash and then press enter.

### Step 2c: Verify the clone in Git Bash

- Navigate into the repo by typing **cd git-academy-sandbox** and pressing enter.

- You should now see the current branch name (e.g. main) at the end of the file path as below:

![](images/git_clone.png){fig-align="center"}

- Type **git log** and press enter to view recent commits. Press **q** when you are ready to exit git log.
- Type **git status** and press enter to check the state of the cloned repository (at this point, it should say everything is up to date, as you haven't made any changes yet).

## Or, to Clone Using RStudio:

### Step 2a: Open RStudio

Open RStudio on your device.

### Step 2b: Clone the Repository in RStudio

- In RStudio, go to **File \> New Project \> Version Control \> Git**.

- Paste the URL you copied from GitHub into the "Repository URL" field.

- Choose a directory on your device where you want to save the repo.

- Click "Create Project".

![](images/R_clone.png){width="467"}

### Step 2c: Verify the Clone

Check the Files pane in RStudio to see if the repo files have been cloned to your local machine. The files pane normally opens in the right-hand bottom corner of RStudio.

![](images/R_files_post_clone.png)
:::

## Conclusion

You have successfully cloned a GitHub repository! Continue on to learn how to create branches.
Binary file added ch2-git-basics/images/R_clone.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 ch2-git-basics/images/R_files_post_clone.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 ch2-git-basics/images/git_clone.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 ch2-git-basics/images/gitbash_here.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 855c05e

Please sign in to comment.