Git Must Know For Open Source Contribution
By: Galit Pauzner
Do you want to start to contribute to an open source project? Not sure how to start? What git commands to use?
Then you came to the perfect place!

In an effort contribute back to the open source community, I found that there are several Git commands to use when working with an open source project.
In this article, I will look on the most common Git commands for the beginner contributor.
I assume you already know how to use Git for version control and that you already have a GitHub account.
Let’s just jump into it :)
Fork repository
To collaborate on an open source project, use the “Fork” button, to create a personal copy of the original repository.
Only after you fork the repo to your personal GitHub user, you can open a pull request to the original repository maintainer(s) who can choose to merge it, give you comments on your code, or disapprove.

Git commands

To start working on the project, you need to create a local clone of the copied fork repository. This can be done by using the GitHub “copy to clipboard” and, in the terminal execute git clone <URL>
. This will create a copy of the repository files in your computer.


Create a new branch called <BRANCH_NAME> as you with a new pointer to the commit.

The git add <FILES_PATH>
, takes the modified changes in your working directory and places them in a staging area before the commit.

The git commit will take the added changes from the staging area of your local repository and associate them with a unique identifier.
The commit requires a message git commit -m <MESSAGE>
that describes the changes you made and why.

The git remote
command lists set of tracked repositories and enable us to manage it. The git remote -v
prints the remote URLs
if you didn’t set up the upstream. The output will show you:
origin https://github.com/[Your_User_Name]/[Your_Fork].git (fetch)origin https://github.com/[Your_User_Name]/[Your_Fork].git (push)

The command git remote add upstream
will connect the original (upstream) repository to the local repository and allows you to sync changes between them.
git remote add upstream https://github.com/[Original_Owner_Name]/[Original_Repository].git
Run git remote -v
again to verify the upstream was added.

The fetch command will download branches and their commits from the remote repository.

The next step is to sync your branch with the changes in the original (upstream) repository. You can do it by executing git merge upstream/main
command, which runs locally on your computer.

The final step would be to push your updated branch from your computer to GitHub. This is done with the git push
command.
To sync the code in your GitHub, push your local <MAIN_BRANCH> to your origin remote GitHub.

The git rebase
command integrates any commits from one branch into another branch. It is an alternative to git merge
command but rebase differs from merge by rewriting the commit history to a linear line.
To understand more about rebasing and learn how to work with it I recommend watching the amazing lecture by Noaa Barkai on the subject (in Hebrew):

The command git cherry-pick
enables you to pick a specific existing commit with commit-hash from another branch. duplicate and apply its content in to your current branch.
This way, you and others can keep track of the origin commit but be careful before using this command. Cherry-pick is mostly used in Hotfixes.
Explore our social media channels:
- https://www.facebook.com/groups/PullRequest/
- On the community’s YouTube page you can find short videos of each of the mentors explaining the project and all the information needed to get started with contributing to open source: https://www.youtube.com/channel/UC9TfgtLt0500BXqPVVmfuTA/featured
- If you want to learn more about Git from a contributor’s eyes, check out our Git playlist on YouTube (Hebrew)
Final Words:
That is all, I hope you enjoyed reading this. If you like this post, I would appreciate applause, comment and sharing :)
Feel Free to connect me on LinkedIn, My name is Galit Pauzner, I am a Software Developer, volunteering in the Pull Request community.
About Pull Request Community
Pull Request community helps developers to get into open-source by connecting them with mentors who care. We aim to provide a safe and friendly environment for contributing to open source projects.