Open In App

Git Workflows With Open Source Collaboration

Open source is a space where people can modify and design something that is publiclycaly accessible to everyone. Software or codebases that are open source facilitate collaboration and innovation, which is not just limited to a team, but the whole public. GitHub is a platform that houses a wide range of projects and repositories from all over the world, enabling developers to contribute to public code, enhance their skills as well as improve the software that they rely on. The project owners also benefit by gaining expertise and innovating ideas from contributors all over the world.

In this article we are going to explore the general workflow followed by contributors while making contributions to public repositories present on GitHub. It is recommended that you create an account on GitHub and install the latest version of git, before commencing with the article. Note: This workflow has been designed keeping in mind the public repositories.



Primary Terminologies

The Git workflow for open-source collaboration typically involves the following steps:

Contribution To GitHub Repository: A Step By Step Guide

Step 1: Fork the Repository



A copy of the repository has been created in the personal account

Step 2: Clone The Repository

git clone https://github.com/TAN347/Game-Aider.git

Step 3: Preparing the Repository

1. Add Remote Upstream

git remote add upstream https://github.com/Tanya347/Game-Aider.git

2. Sync With Upstream

Note: this won’t update you forked repository present on your account. It directly updates the local repository on your machine. If you want to update your forked repository, then you can always push the new changes using git push command.

git fetch upstream
git merge upstream/master
git pull upstream

3. Create a Branch

In this tutorial, we will change the following button on the Truth and Dare page by making it slightly bigger and the font more bold:

Button to be changed

Create a new branch for your feature or bug fix. It’s best practice to create a branch for each new feature or issue you’re working on. The branch name should be short, descriptive and unique.

git checkout -b feature-branch

Step 4: Make Changes In Working Area

git status

git add .
git commit -m "Add feature or fix bug"

Note: git add . command adds all the files with changes to the staging area. If you don’t want that and just want one or few select files to be staged, then you can do it like this:

git add <file_name1> <file_name2> <file_name3>

Step 5: Push Changes to Your Fork

git push origin feature-branch

Step 6: Create Pull Request

Step 7: Review and Iterate

Step 8: Merge And Delete

git push origin --delete feature-branch

GitWorkFlows – FAQ’s

What are the three stages of Git Workflow?

The three stages of Git Workflow are: modified, staged, committed.

Why is a forked repository required?

Forking a repository creates a copy of the original repository under your GitHub account. It allows you to freely experiment with changes without affecting the original project. You can also contribute to the project by submitting pull requests from your forked repository.

How to keep the forked repository synced with the original repository?

To keep your forked repository in sync with the original repository, you need to add the original repository as a remote (upstream). Then, you can fetch changes from the original repository and merge them into your local branch. Finally, you can push the changes to your forked repository.

Is creating a new branch compulsory for a new feature or bug fix?

Creating a new branch for each feature or bug fix isolates your changes from the main codebase, making it easier to manage and review. It also allows you to work on multiple features concurrently without interfering with each other.

How to handle merge conflicts when a pull request is created?

Merge conflicts occur when there are conflicting changes between your branch and the target branch. You need to resolve these conflicts by manually editing the affected files to reconcile the differences. Once resolved, you can commit the changes and continue with the pull request process.


Article Tags :
Git