6. Forks
When you want to contribute to a project, you can't create branches directly in the original repository (unless you've been given permissions beforehand). Instead, the most standard way to contribute is by making a fork.
A fork is a complete copy of a repository. It lets you experiment without affecting the original project, freely creating and modifying (branches, commits, etc.). Once you've finished your changes, you can ask the original repository to accept your modifications through a Pull Request (a merge between your fork and the original repository).
How to create a Fork
- Go to the repository you want to contribute to
- Click the "Fork" button (top right)
- GitHub will create a copy in your account
- Now you have your own version of the project
Next, you can clone your fork locally:
# Clone your fork
git clone git@github.com:your-user/project.git
cd project
# Add the original repository as "upstream"
git remote add upstream git@github.com:original-user/project.git
# Verify
git remote -v
Now you'll have two remotes:
- origin: Your fork
- upstream: The original repository
Sync a fork with upstream
Over time, the original repository will have changes that your fork doesn't have. You need to sync them.
# 1. Get changes from upstream
git fetch upstream
# 2. Switch to your main branch
git switch main
# 3. Merge changes from upstream
git merge upstream/main
# 4. Update your fork on GitHub
git push origin main
GitHub also has an easy way to sync your fork from the web interface:
- Go to your fork on GitHub
- Click "Fetch upstream"
- Select "Fetch and merge"
A good practice is to sync before starting to work on each new feature.
Explore the code
Before contributing, familiarize yourself with the project:
# View the project structure
tree -L 2
# Read the main code
cat src/main.js
# View the change history
git log --oneline -n 20
# See who has contributed
git shortlog -sn
# Explore a specific feature
git log --oneline -- path/to/file.js
# View active branches
git branch -a
Activity 1
- Find an open source project that interests you on GitHub.
- Read its README, CONTRIBUTING and CODE_OF_CONDUCT.
- Identify which license it uses.
- Look for issues.
- Create a fork of the project.
- Clone your fork locally.
- Add the upstream and sync your fork.
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Desafíos de programación atemporales y multiparadigmáticos
Te encuentras ante un librillo de actividades, divididas en 2 niveles de dificultad. Te enfrentarás a los casos más comunes que te puedes encontrar en pruebas técnicas o aprender conceptos elementales de programación.
Buy the bookWill you buy me a coffee?
This is how I keep writing without ads or paywalls.
Sure, it's on me!
Comments
There are no comments yet.