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 :)
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.
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.
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.
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)
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
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.
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):
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:
- 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)
That is all, I hope you enjoyed reading this. If you like this post, I would appreciate applause, comment and sharing :)
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.