To create a PR (Pull Request), I used a Fork & Branch Git Workflow mentioned below:
Prerequisites:
- GitHub account
- Git installed in local machine
Guidelines:
- Every other open source project has its own set of guidelines to follow before creating a PR. So, please
go
through the project details & make changes as per the rules.
Terminologies:
- Local: It typically means "on our computer".
- Remote: It is the code hosting service like Github,
Bitbucket & others.
Step 1: Fork the Repository
- Open the original repository in GitHub.
- Click on the Fork in the top right corner (below your profile icon).
- In a matter of seconds, it will be ready with your forked repository.
Step 2: Make a Local Clone
- In your local machine, move to the location you want to clone your forked repository.
Right-click and choose Git Bash Here option. This will open the Git terminal.
- Type
git clone {URL of forked repository}
- In a matter of seconds, it will be ready with your forked repository.
Note:
- "URL of forked repository" will be unique for every user. You can find it
under Code > HTTPS in your
GitHub account inside the forked repository.
- For any repository, default Git remote name is origin
- Syntax:
cd {repository-name}
to enter the cloned
repository.
Step 3: Adding a Remote
- Syntax:
git remote add upstream
{URL of original repository}
Note:
- Git remote name to pull changes from the original repo is
upstream here.
- You can name it
anything.
We will need it at a later point.
Step 4: Working In a Branch
- Create and Checkout
Method 1
git branch {branch-name}
git checkout {branch-name}
OR
Method 2 (shorthand for Method 1)
git checkout -b {branch-name}
Example: git checkout -b feature
Executing either method creates & switches to the new branch i.e feature.
- Make changes to the files via any editor of your choice
Any changes made will be in the feature branch, not main (formerly known as the master)
a.k.a root branch.
- Commit those changes
git add .
git commit -m "{message}"
Step 5: Pushing changes to GitHub
- Syntax:
git push {remote}
{branch}
git push origin feature
Step 6: Opening a Pull Request
- GitHub makes it incredibly easy.
Click on Compare & Pull Request button.
-
Provide a brief title & description.
Click on Create Pull Request to submit.
- Wait for it to be merged.
Step 7: Cleaning Up After a Merged PR
Step 8: Keeping your Forked Repo in Sync with the Original Repo
- It's recommended to do this every time before raising a PR / time-to-time to
update your Forked Repo > main branch
git pull upstream main
git push origin main