8.2: GitHub Fork and Clone
At the end of this lesson, you should:
- Be able to use the GitHub Fork feature.
- Be able to use the
- Be able to use the
We will learn more features of Git and GitHub to start and submit SWE 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.
In the below video we demonstrate
git push origin master, but for SWE Fundamentals
git pushwill suffice.
originrefers to the target Git remote, and
masterrefers to the target branch. Rocket Academy has updated our repos to use
mainas the default branch name as per GitHub's latest convention, so if you wanted to specify the full command including remote and branch for SWE Fundamentals, you could use
git push origin main.
"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.
"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.
We'll use a Git command to download or "clone" a copy of SWE 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.
<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.
git clone <REPO_DOWNLOAD_URL> <LOCAL_REPO_FOLDER_NAME>
git clone https://github.com/rocketacademy/fundamentals-starter-code.git fundamentalsash-starter-code-test
Clone a repo onto your computer from GitHub
GitHub enables us to coordinate differences between local and "official" versions of the code, but we won't concern ourselves with that just yet.
We will learn 1 new Git command
pushto send local code commits from our computers to GitHub.
pushcan also be used as a general command to move code between "remote" repos, but during SWE Fundamentals we will only be using
pushto push code to GitHub.
The "git push" command can be used to send local code commits to GitHub.
Here is the workflow for SWE 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.
git pushour changes to our repo. Refresh the repo page to see our commits in the repo.
- 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 pushto update your GitHub repo.