21
How to Make an Open Source Github Contribution 👯♀️
In this post, we'll go over the basics of how to make your first Github contribution. If you would like to test out your skills, and make a test contribution, head over to Merge Me, an open source repository that allows you to practice making your first pull/merge requests. You'll find these same directions once you open up the index.html file. Let's get started!
Fork and clone the repository to your local environment.
Start by making a pull request. This will keep all the files locally up-to-date with the remote repository, in the circumstance other developers you may be working with have made any new changes. To do this, start off by confirming you are in the main branch, and then in your command line type:
user@Users-MacBook_Air: git pull origin main
Running this command will pull all the files from the remote branch, updating your local branch to match any changes made. It's always a good idea to do this, especially when working with others as you don't know what changes could have been made since you last accessed the branch.
- After you've confirmed everything is up-to-date, you're going to check out a new branch, this will be your staging area. If you're adding a new feature to any application, you want to preserve its original state, this avoids big bugs and annoyed developers down the line. To do this, in the command line type:
user@Users-MacBook_Air: git checkout -b (YOUR BRANCH NAME)
When naming your branch, it's good practice to name it after what you're doing/in relation to the changes being made. So, if you were to make a pull request to add a README.md file into a repo, you might name that branch 'readme-md'.
If you've done it correctly, you should have received the following message in your terminal:
switched to new branch '(YOUR BRANCH NAME)'
Once you are inside your newly created branch, you can finally add in your own code! So, contribute! Go! Be Free!
After you've made the most meaningful contributions of your life, you're going to want to save all those beautiful changes. Now we're going to do something that should hopefully feel a little familiar. In your terminal type:
user@Users-MacBook_Air: git add .
- Followed by, you guessed it, 'git commit'. While you may not always make the most meaningful commit messages for your own code/repositories, (even though you should), you ALWAYS have to make meaningful commit messages when contributing to another developer's code or in your work place. Not only is it professional and coder common courtesy, it also gives an idea as to what was done with the code at that staging period. This helps decrease debugging time and everyone else will understand what the heck is going on inside the application.
user@Users-MacBook_Air: git commit -m "A MEANINGFUL COMMIT MESSAGE EXPLANING WHAT YOU ADDED"
- WAIT! DON'T PUSH IT YET! (I had to add this in here for those of us who like to jump ahead sometimes) Now that I hopefully have everyone's attention, you never want to just push your contribution up to the main branch. This goes back the coder common courtesy and professionalism explained before. Not to mention, you may have some unhappy developers if you overwrote/added code that wasn't approved of first.
To avoid this, you'll instead push your changes to your newly created branch. This can be done by adjusting the good ol' 'git push' command to the following:
user@Users-MacBook_Air: git push origin (YOUR BRANCH NAME)
You should receive a message back in your terminal confirming that your code was pushed up to your newly created branch.
- If you head on back over to the repository you're working on, you should see new notification that the repository was recently updated, along with your branch name. There should also be a button that says 'Compare & pull request'. Go ahead and click it.
You should be lead to a page that displays your commit message! You'll see an option to leave a message underneath your commit. If you are working with others, it is great coder common courtesy to leave a nice little message further detailing your commit and why you added it in the first place. Again, this avoids bugs and confusion later.
After you've left a message, you're going to create a pull request. You should see a 'Create pull request' button underneath the message box, give that a click. By doing this, you're putting a request to the repository owner that you would like to push your changes to the main branch of the repository. Doing so will also notify all the other developers working on this repository that a new push request has been made. You can even assign reviewers to be notified of your push request, which can be done under the 'reviewers' tab.
If everything went smoothly and you contributed something (somewhat) meaningful, your code will get pushed, merging with the main branch.
Congratulations, you just made your first contribution. Do a dance to celebrate.🎉
It doesn't seem so bad after all, does it? If you followed along with this post while making your first contribution, awesome job! If you haven't made yours yet, get on out there and do it! Try it out on the Merge Me, where you can collaborate with other developers like you!
I hope this blog post has helped you in your contribution journey, as much as I hope to see your contributions in Merge Me, happy coding! :)
21