# 8.2: GitHub Fork and Clone

## Learning Objectives

* Be able to use the GitHub Fork feature
* Be able to use the `git clone` command
* Be able to use the `git push` command

## Introduction

We will learn more features of Git and GitHub to start and submit Coding Fundamentals projects. As a reminder, Git is the *version control system* and GitHub is the code-hosting website built on top of Git. GitHub extends the capabilities of Git by adding visual code browsing, social features, and collaboration features.

{% hint style="warning" %}
In the below video we demonstrate `git push origin master`, but for Coding Fundamentals `git push` will suffice. `origin` refers to the target Git remote, and `master` refers to the target branch. **Rocket Academy has updated our repos to use `main` as the default branch** name as per GitHub's latest convention, so if you wanted to specify the full command including remote and branch for Fundamentals, you could use **`git push origin main`**.
{% endhint %}

{% embed url="<https://youtu.be/uMNcnLWTmZU>" %}

### GitHub Fork

"Fork" is the GitHub term for *copying* a repo from one GitHub account to another. We can fork a repo by clicking the Fork button on a given GitHub repo page. Forking allows us to make changes to a repo and save those changes to *our own* GitHub account's copy of the repo. Our account's repo is essentially ***independent*** from the original, forked repo.

![How to find the fork button on a repo page.](https://3179661644-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4q5CU5JQTFABt9tKnZLj%2Fuploads%2Fgit-blob-a31ad0ebbfda5edfdd61dd7716f73838477803d2%2Fscreen-shot-2020-08-19-at-10.23.10-pm%20\(1\)%20\(2\)%20\(3\)%20\(1\)%20\(2\)%20\(1\).png?alt=media)

"Fork" is a GitHub concept. Forking is not built-in to the Git version control system.

![A "fork" is when we copy a repo from another account to our own inside of GitHub.](https://3179661644-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4q5CU5JQTFABt9tKnZLj%2Fuploads%2FxqlxalIGHyx21CJJG3lH%2Fgithub-fork.png?alt=media)

## Git Clone

We'll use a Git command to download or "clone" a copy of Coding Fundamentals starter code. `<REPO_DOWNLOAD_URL>` is the download URL of our repo, obtained by clicking the Download Code button on the repo's [GitHub page](https://github.com/rocketacademy/fundamentals-starter-code). `<LOCAL_REPO_FOLDER_NAME>` is the name of the destination folder that is created (containing the contents of the repo) when we run the Git command.

**Command Template**

```
git clone <REPO_DOWNLOAD_URL> <LOCAL_REPO_FOLDER_NAME>
```

**Sample Command**

```
git clone https://github.com/rocketacademy/fundamentals-starter-code.git fundamentals-starter-code-test
```

![Clone a repo onto your computer from GitHub](https://3179661644-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4q5CU5JQTFABt9tKnZLj%2Fuploads%2FrYl3PvVYBjSV6iJuL1VT%2Fgithub-clone.png?alt=media)

GitHub enables us to coordinate differences between local and "official" versions of the code, but we won't concern ourselves with that just yet.

### Git Push

We will learn 1 new Git command `push` to send local code commits from our computers to GitHub. `push` can also be used as a general command to move code between "remote" repos, but during Coding Fundamentals we will only be using `push` to push code to GitHub.

![The "git push" command can be used to send local code commits to GitHub.](https://3179661644-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4q5CU5JQTFABt9tKnZLj%2Fuploads%2FTpkNIAz291mFMyIIk0br%2Fgithub-push.png?alt=media)

## Cheatsheet

Here is the workflow for Coding Fundamentals projects:

1. Go to the project repo page. Click the "Fork" button to copy the repo to our own GitHub account.
2. In the command line on our local computer, **clone the repo from our own Github account's copy of the repo.**
3. Once the repo is on our computer, make the changes we want, and follow the Git workflow and [cheatsheet ](https://fundamentalslite.rocketacademy.co/7-version-control/7.1-git#cheat-sheet)to commit those changes.
4. `git push` our changes to our repo. **Refresh** the repo page to see our commits in the repo.
5. Create a [pull request](https://fundamentalslite.rocketacademy.co/8-github/8.3-github-pull-request) in GitHub. This connects our work on the repo *in our account* to the original Rocket Academy repo. Fill in the survey and submit.

## Exercise

1. Fork a copy of the [Fundamentals Beat That! repo](https://github.com/rocketacademy/basics-beat-that) as setup for Project 2.
2. Clone the repo into a folder on your local machine.
3. Once you start working on your project, make frequent commits and use `git push` to update your GitHub repo.
