# GitHub Forking
> [!tip] Tips
>
> - Always pull the latest changes from upstream before starting on new changes.
> - Make sure your PR is concise; only include changes relevant to the issue you are addressing.
## 1. Fork the repository
**Forking** is the process of creating a copy of the original (upstream) repository on your GitHub account. This allows you to freely experiment with changes without affecting the original project.
- Navigate to the GitHub page of the repository you want to contribute to.
- Click on the **Fork** button at the top right corner of the page.
## 2. Clone the forked repository
- On your fork’s GitHub page, click the **Code** button and copy the URL provided.
- Open a terminal and run the `git clone` command with your URL:
```shell
git clone <URL_OF_YOUR_FORK>
```
- Navigate into the cloned directory:
```shell
cd <REPOSITORY_NAME>
```
## 3. Add the upstream repository
To keep your fork up to date, you need to specify the original repository as an **upstream** remote.
- Inside your local repository, add the upstream remote:
```shell
git remote add upstream <URL_OF_ORIGINAL_REPOSITORY>
```
- Verify the new upstream repository you've specified for your fork:
```shell
git remote -v
```
## 4. Create a new branch
Branches help isolate your changes for a specific feature or fix from other work in the repository.
- Create and switch to a new branch:
```shell
git checkout -b <YOUR_BRANCH_NAME>
```
## 5. Make changes and commit
Make your changes in the local repository. After making changes:
- Stage the changes for commit:
```shell
git add .
```
- Commit the changes:
```shell
git commit -m "Your detailed commit message"
```
## 6. Push changes to GitHub
After committing your changes, push them to your fork on GitHub.
- Push the changes:
```shell
git push origin <YOUR_BRANCH_NAME>
```
## 7. Create a pull request (PR)
**Pull Requests** are the way your changes will be reviewed before they are merged into the original project.
- On your fork’s GitHub page, navigate to **Pull requests** > **New pull request**.
- Select your branch and compare it to the original repository’s branch you want to contribute to.
- Review the changes, fill in a description for your changes, and submit the pull request.
## 8. Stay in sync with upstream
To keep your fork up to date with the original repository:
- Fetch the upstream changes:
```shell
git fetch upstream
```
- Merge the changes from upstream/master (or main) into your local master branch:
```shell
git checkout master
git merge --ff-only upstream/master
```
- Push the latest changes to your fork:
```shell
git push origin master
```