Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Push a Project and Contribute on GitHub?

  • Last Updated : 26 Nov, 2021

Github is a basic platform used by programmers all over the world to create and contribute to open-source projects. For contributing to other projects over Github, we need to open a pull request, which is accepted by the maintainer of the repository or project if he finds that change or contribution effective. Here, we are going to learn about creating a new pull request on GitHub open-source projects. For this, we need to follow these basic steps:

How to contribute to a repository?

First of all, we need to fork the repository on which we want to contribute to our own Github account. It can be done by clicking the fork option near the top-right corner of the repository. 

After that, we need to open the files of the forked repository on our local PC. For this, we can use Terminal or open Git Bash on that folder, which can be installed separately on our PC. Create a new folder, where we want to store the files from the repository, and then we need to run the following commands:

git init
git remote add origin "link to your forked repository"
git pull origin "branch name"

This will pull all the files from your forked repository to our local PC folder. Here, a typical “link to your forked repository” looks like this:

The command in the Git Bash will be:

If the repository has more than one branch, then we can shift our branches by running the following command in our Git Bash terminal:

git checkout "branch name"

For checking the branch name we are currently in, we need to run this command:

git branch

For example, if we are in the dev branch and we want to shift to the master branch, then we will use this command:

git branch
git checkout master
git branch

The output of the following command will be like this:

* dev
* master

Thus, in this way, we can change our branch in our local folder.

How to save our changes to our forked repository?

To add all the changes we made in our code to the local repository, we need to log in to our Github account in Git Bach and run the following command in Git Bash:

git add .
git commit -m "test commit"
git push -u origin "branch name"

If the branch name is master, then the last command would be:

git push -u origin master

This successfully copies all the updated files to our forked repository. We can also add files selectively using the specific file name which we want to push in our forked repository. We can check the files which are updated by running the command:

git status

This shows all the files that are updated by the user which are yet not committed. If the file name is “upgraded.js”, then the command will be:

git add upgraded.js
git commit -m "saving changes"
git push -u origin "branch name"

How to create a pull request to the original repository?

Only after we made certain changes and upgradations in our forked repository, the option to Open pull request will be visible on clicking Contribute button that indicates that your forked repository has some commits/upgradations that are yet not added to the original repository. Click on the contribute button, and it will open a page that allows us to open a pull request and set the name of your pull request, and you can write some additional description about the changes made. After submitting the pull request, the request is sent to the maintainer/owner of the original repository, which may be accepted if the maintainer likes the changes/upgrades made by us.

Click on the contribute button once changes are made in the forked repository

Creating a successful pull request

Here, we can write some description about our changes and finally open a pull request

Once he accepts the request, our changes will be visible in the original repository and thus, we successfully contributed to a project.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!