0
0
Gitdevops~10 mins

Fork and pull request workflow in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Fork and pull request workflow
Fork repository
Clone fork locally
Create new branch
Make changes & commit
Push branch to fork
Open pull request
Review & merge by original repo
Pull updates to local repo
This flow shows how you copy a repo (fork), work on your copy, then ask the original repo to add your changes via a pull request.
Execution Sample
Git
# Fork repository on GitHub UI
git clone https://github.com/yourname/repo.git
git remote add upstream https://github.com/original/repo.git
git checkout -b feature-branch
# edit files
git commit -am "Add feature"
git push origin feature-branch
# open pull request on GitHub
Commands to fork a repo, clone it, create a branch, commit changes, push, and open a pull request.
Process Table
StepActionCommand/DescriptionResult/State Change
1Fork repositoryFork on GitHub UIYour GitHub account has a copy of the original repo
2Clone fork locallygit clone https://github.com/yourname/repo.git git remote add upstream https://github.com/original/repo.gitLocal copy of your forked repo created, upstream remote added
3Create new branchgit checkout -b feature-branchNew branch 'feature-branch' created and checked out
4Make changes & commitEdit files + git commit -am "Add feature"Changes saved in local branch with commit
5Push branch to forkgit push origin feature-branchBranch and commits uploaded to your GitHub fork
6Open pull requestOpen PR on GitHub from feature-branch to original repoPull request created for review
7Review & mergeOriginal repo maintainer reviews and merges PRChanges merged into original repo
8Pull updates locallygit checkout main git pull upstream mainLocal repo updated with merged changes
9ExitWorkflow completeYour changes are now part of the original repo
💡 Pull request merged and local repo updated, workflow ends
Status Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 7Final
RepositoryOriginal repo onlyForked repo cloned locallyBranch 'feature-branch' with changesBranch pushed to fork on GitHubPR merged in original repoLocal repo updated with merged changes
Branchmainfeature-branch createdfeature-branch with commitfeature-branch on fork remotefeature-branch merged to mainmain updated locally
Key Moments - 3 Insights
Why do we create a new branch instead of committing directly to main?
Creating a new branch isolates your changes so the main branch stays stable. See execution_table step 3 and 4 where the branch is created and commits happen there.
What happens if you push changes directly to the original repo?
You usually can't push directly unless you have permission. Forking lets you work independently. Step 5 shows pushing to your fork, not original repo.
Why do we pull updates from the original repo after merging?
To keep your local copy up to date with the original repo's latest changes. Step 8 shows pulling updates after PR merge.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step is the new branch created?
AStep 2
BStep 5
CStep 3
DStep 6
💡 Hint
Check the 'Action' column for branch creation in the execution_table.
At which step does the pull request get merged into the original repo?
AStep 4
BStep 7
CStep 5
DStep 8
💡 Hint
Look for 'Review & merge' action in the execution_table.
If you skip pushing your branch to your fork, what will happen when opening a pull request?
APull request will fail to open
BPull request will show no changes
CPull request will merge automatically
DPull request will open but be empty
💡 Hint
Refer to step 5 and 6 in execution_table about pushing branch before opening PR.
Concept Snapshot
Fork and pull request workflow:
1. Fork repo on GitHub to create your copy.
2. Clone your fork locally.
3. Create a new branch for your changes.
4. Commit and push changes to your fork.
5. Open a pull request to original repo.
6. Original repo reviews and merges your changes.
Full Transcript
The fork and pull request workflow starts by copying a repository on GitHub (fork). Then you clone your fork to your computer. Next, create a new branch to keep your work separate from the main code. Make your changes and commit them locally. Push this branch to your fork on GitHub. Open a pull request from your branch to the original repository to ask for your changes to be added. The original repo maintainer reviews and merges your changes. Finally, pull the latest changes to keep your local repo updated. This workflow helps keep the original project stable while allowing many people to contribute safely.