GitHub Basics: Forking, Pull Requests, and Keeping Repositories in Sync

GitHub is an essential tool for collaboration in software development. Whether contributing to an open-source project or collaborating with a team, understanding how to fork, create pull requests, and keep your repository up-to-date is crucial. This guide provides a step-by-step approach to effectively manage these tasks.

1. Fork the Repository

  • Go to the GitHub page of the repository you want to contribute to.
  • Click the Fork button in the upper-right corner. This creates a copy of the repository in your account.

2. Clone the Fork

  • Clone your forked repository to your local machine:
git clone https://github.com/your-username/repository-name.git

cd repository-name

3. Create a New Branch

  • Before making changes, create a new branch to work on:
git checkout -b feature-branch-name

4. Make Changes and Stage Them

  • Edit files as needed. Once you’ve made your changes, stage them:
git add .

Or stage specific files:

git add filename

5. Commit Changes

  • Write a descriptive commit message summarizing your changes
git commit -m "Describe your changes here"

Pushing Changes and Creating a Pull Request

Once your changes are committed locally, the next step is to push them to your fork and submit a pull request.

1. Push Changes to Your Fork

  • Push the changes in your branch to your forked repository:
git push origin feature-branch-name

2. Create a Pull Request

  • Navigate to your fork on GitHub.
  • Click the Compare & pull request button.
  • Add details about your changes, such as what problem you solved or feature you added.
  • Submit the pull request to the original repository.

Keeping Your Fork Up-to-Date

To avoid conflicts and ensure your fork is in sync with the original repository, you’ll need to periodically pull updates.

1. Add the Original Repository as a Remote

  • Add the original repository (upstream) as a remote:
git remote add upstream https://github.com/original-user/repository.git

Verify the remote was added:

git remote -v

2. Fetch Updates from Upstream

  • Fetch updates from the original repository:
git fetch upstream

3. Merge Updates into Your Branch

  • Merge changes from the main branch of the original repository:
git merge upstream/main

Replace main with the branch name you are syncing, if it’s different.

4. Resolve Conflicts

  • If there are conflicts, Git will highlight the affected files. Open them, resolve the conflicts, and stage the changes:
git add .
git commit -m "Resolved merge conflicts"

5. Push Changes to Your Fork

  • Update your fork with the synced changes:
git push origin main

Pulling the Latest Changes Before Making New Contributions

Before starting new work, always pull the latest changes from the original repository to avoid working on outdated code.

  1. Switch to Your Branch
git checkout main


2. Pull Updates

git pull upstream main

Best Practices for GitHub Contributions

  • Write Clear Commit Messages: Ensure your commit messages describe the purpose of the changes.
  • Follow Project Guidelines: Check the repository’s contribution guide for coding standards and practices.
  • Test Your Changes: Run tests locally to verify your changes before creating a pull request.
  • Stay Updated: Regularly sync your fork with the original repository to avoid conflicts.


Mastering these GitHub workflows will help you contribute effectively to projects, maintain a clean development process, and collaborate seamlessly with others. By following these steps, you’ll be well-equipped to navigate any GitHub repository with confidence.


Discover more from MountAviary

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *