A short guide to creating clean, well-managed GitHub contributions.

In this article, I’ll give you 10 simple steps to make sure GitHub’s contributions are fast and clean.

Contribution lifecycle (steps)

1. The fork main warehouse

Fork the main repository creates a copy in your account. You can make changes and push any code to this fork without worrying about messing up the original code base. Click the fork button at the top of the page to create a new fork.

The post-fork repository is now available in the “Repositories” section of your account.

2. Clone the warehouse after Fork to your computer

The repository after the Fork is cloned to the computer so that we have a local copy of the code. Click the clipboard icon next to the SSH or HTTPS URL of the repository after Fork to copy it.

Now open a terminal on your computer and run the following command to clone fork’s repository:

git clone [email protected]:theawesomenayak/guava.git
Copy the code

3. Create a feature/feature branch

When making any changes to the code, it is best to create a new feature branch for the changes we need to make. This ensures that we keep the Master branch clean and can easily restore our code or update it if necessary.

Directory created after switching to clone branch repository:

cd guava
Copy the code

Create a new feature branch with a name that identifies the changes you plan to make. Such as:

git checkout -b fix-npe-issue
Copy the code

4. Commit changes to the feature branch

If you create any new files as part of your change, you need to add them to the branch you just created.

git add <filename>
Copy the code

For all changes you make, you must commit them to the branch. Make sure to add a valid commit message (according to the project’s conventions) :

git commit -m "Fixed the NPE issue due to a null key used in cache"
Copy the code

5. Push the feature branch to the repository at your fork

Now it’s time to push your submission to fork’s repository:

git push origin fix-npe-issue
Copy the code

6. Pull Request (PR) for the main warehouse

After pushing the code to the forked repository, you can commit PR against the main repository. Click the Pull Request button to launch the new PR.

This will take you to a screen where the changes in your fork library are compared to the code in the main library. You can view the changes and provide a valid description of the changes before committing them.

7. Handle reviews and incorporate PR

The code maintainer will usually return some comments about the changes you’ve made, either functional or cosmetic, such as formatting, and so on. Once you have made these changes, just push them to your branch and the PR will update automatically.

Once your changes are in order, the maintenance staff will merge them into the main repository. Congratulations!! You are now officially an open source contributor.

8. Add the primary repository upstream to the clone repository

Many other developers besides you have been merging their code into the main repository, and we need to continuously synchronize with its branch to get the latest code.

Your cloned repository is already linked to the fork repository. To keep the fork repository in sync with the main repository, you need to connect them by adding the main repository as upstream to the cloned repository.

git remote add upstream [email protected]:google/guava.git
Copy the code

Verify that the upstream Settings are correct using the following command:

git remote -v
Copy the code

It should display the following values to confirm that the source and upstream point to the correct repository:

origin  [email protected]:theawesomenayak/guava.git (fetch)
origin  [email protected]:theawesomenayak/guava.git (push)
upstream        [email protected]:google/guava.git (fetch)
upstream        [email protected]:google/guava.git (push)
Copy the code

Update your Master branch from upstream

With upstream set, you can extract changes made by other developers in the main repository, which will update the clone repository on the local computer:

git pull upstream master
Copy the code

10. Push the main branch to your fork repository

Once you have all the updates on your local machine, you will need to push them to the repository behind your fork to synchronize them with the main repository.

git push origin master
Copy the code

(Optional) Delete a feature branch

After the feature is merged into the main repository, it is no longer needed and can be removed:

git branch -d fix-npe-issue
Copy the code

You can also remove remote branches from fork’s repository:

git push origin --delete fix-npe-issue
Copy the code

The last

Contributing to the GitHub project can be tricky, depending on how many developers are working at the same time. Hopefully this article clears up the GitHub contribution process for you and makes your development cycle a little easier.

Thank you for taking the time to read my article.


Original text: medium.com/better-prog…

Public account “Front-end Full Stack Developer”