SyntaxStudy
Sign Up
Git Fork, Clone, and Pull Requests
Git Beginner 11 min read

Fork, Clone, and Pull Requests

GitHub's collaborative workflow: fork a repository to get your own copy, clone it locally, make changes on a branch, push to your fork, then open a Pull Request (PR) to propose merging your changes into the original repository.

Example
# 1. Fork the repo on GitHub (click the Fork button)
#    This creates: github.com/YOUR-USERNAME/original-repo

# 2. Clone your fork locally:
git clone git@github.com:YOUR-USERNAME/original-repo.git
cd original-repo

# 3. Add the original repo as 'upstream':
git remote add upstream git@github.com:ORIGINAL-OWNER/original-repo.git
git remote -v
# origin   git@github.com:YOUR-USERNAME/original-repo.git
# upstream git@github.com:ORIGINAL-OWNER/original-repo.git

# 4. Create a feature branch:
git switch -c fix/typo-in-readme

# 5. Make changes, stage, and commit:
git add README.md
git commit -m "fix: correct typo in installation section"

# 6. Push to your fork:
git push -u origin fix/typo-in-readme

# 7. Open a Pull Request on GitHub
#    (GitHub will show a prompt after pushing)

# 8. Keep your fork up to date with upstream:
git fetch upstream
git switch main
git merge upstream/main
git push origin main