Cloning a repository
To work on the contents of an existing Git repository, the first step will often be to “clone” it to your local working environment (i.e. your laptop!).
To clone a repo, you’ll first need to find the necessary URL.
Go to the git-academy-sandbox repository page on GitHub.
Click the “Code” button and copy the URL (HTTPS link).
Navigate to the folder on your device where you want to clone the repo. Right-click in the directory and select Git Bash Here.
- 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:
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.
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:
- 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).
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”.
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.