Github 101
Tags: github, git, opensource, contribution
Published: 2021-05-25 14:59:59

In the last blog, I have shared the information about a general abstract knowledge of what opensource is and what we can do to contribute etc. For those who haven't read that blog can see it [here](https://dev.to/honeybhardwaj/introduction-to-opensource-24di).

Since that blog didn't had a knowledge about how to contribute or how to setup everything, I ll cover all that here in this particular blog. So this blog will cover all the necessary things required to start your very first contribution in open source project. 

note: This is a practical blog/tutorial so you can follow along and can get a practical overview about contributing in opensource.
<hr>
# what is git and github? 
Git is distributed version control system used by software developers contributing on a single project or software. Basically it helps users to track down the different changes made to the software by different users.

Github is a platform that provides hosting and version control for your code and anyone can colaborate on any project all over the world.
<hr>
# Getting started with Github 

The first and the primary step is setting up the environment for which you would be needed to download git in your system.You can download the git for your specific operating system form [here](https://git-scm.com/downloads). 
![download github](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ojyu2xl47ldwyud8bunz.png)

once you have successfully installed git in your system you can open your command prompt and type the following command to check.
```bash 
git --version
```

after this you can go to [Github's website](https://github.com/) and can create an account if you dont have. once you have an account on github with git installed in your pc, You are all set to go.

Your account will look similar to something like this:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tu646cy7zxsif6207pqn.png)
So there are certain steps you need to follow to start contributing on github:
1. Creating a Repository.
2. Forking a Repository.
3. Cloning  a Repository.
4. Creating commits.
5. Adding origin/Upstream.
6. Pushing code to origin.
7. Creating branch.
8. Creating issues.
9. Creating a pull request.
10. Updating your contents of the repo.
<hr>

### Creating a Repository 
A repository is a single folder that contains the necessary files required for the project. we can say it as an alternative name for directory. For creating a repo you can see the top right corner of your window where you will have an option to create repository as shown in the fig. below:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cbp3bvnu8v4yreh2gs9h.png)
once you have clicked you need to fill some information about the repo such as its name, if you want to include Readme file or not or include any files etc. ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/djot377vqklmxl5sb823.png).
<hr>

### Forking a Repository
So whenever you want to contribute in some project of some other person on organization. The first step is to fork the Project that is creating a copy of files of that project for your github account. This needs to be done since you will be changing the files of the project and you don't want that it should affect the original project.
You can locate the button to fork on the top right when you open a particular project as shown in image below:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/woftme7ym2b3ue3sv7nf.png)
<hr>

### Cloning a Repository
For setting up environment in your local pc the first need is downloading the files in your pc to run them. this process is known as clonning a repo . you can open your terminal and go to the follwing path where you want to clone files then do the following command:
```bash
git clone <url of the repo>
```
<hr>

### Creating Commits
a commit is basically an event that enables you record the state of the project or save the changes. this is the operation that you performs all the time. there change that needs to be commited must be staged first. the commands of the following are:
```bash
git add <filename>
git commit -m "type your message here"
```
<hr>

### Adding origin and upstream
once you have made the changes in the repo and you want to push it into the github account or any remote account . you will be needed to add origin or upstream for the particular project . since you had cloned your project so the origin of the project will be already set. to view that you can type the following command:
```bash 
git remote -v
```
if you dont see anything printed on your terminal then you need to add them. origin is the acronym used for your account from which you have to clone or the place where you need to push the code. upstream is the remote location from which the project have been forked. to add origin and upstream you can do the following commands:
```bash
git remote add origin <link of origin repo>
git remote add upstream <link of upstream repo>
```
<hr>

### Pushing Code To Origin
once you have done everything that was required to change in the local repositry you can update the content of the repo in github by pushing the code to github or uploading it. we can do so by following command:
```bash 
git push origin main
```
This will ask you for your userid and password of your github account.Here origin is the location where the files need to be pushed and main is the branch  which needs to be pushed.we will know about branch in the later section .
<hr>

### Creating Branch
Since You know that whenever we develop any software or project we do often create new features or fix a bug so we uses branches for that. It is basically a way to maintain the difference in original code with respect to new feature or a bug fix. For checking the existing branch in the project we can type the following command:
```bash
git branch -a
```
To create a new branch we can run the following command in the terminal
```bash
git branch <name of new branch>
```
To checkout or change the current branch you can use the following command
```bash
git checkout <name of branch>
```
It is a good practice to create a new branch for every issue created.
<hr>

### Creating Issues
Once you contribute in any opensource project there is a section in github for issues where you can create an issue. issue basically resembles the particular bug you found in the project or any enhancements for the project or if you need any help from anyone from the community.
In an active project there must be many active issues created by members. if you like to work on any issue you can comment on that issue that you are interested to work on it. The project admin or maintainers will assign the issue to you, Then you can start working on it.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0eimic68trvco5d4233e.png)
<hr>

### Creating pull Request
For getting the opinion about the contribution that you have made from the collaborators you needed to create a pull Request which describes the changes that you have made.some organizations also have some template or the format that one needs to follow while creating a pull request.
<hr>

### Updating The Contents Of The Repo.
In a system which is open to collaboration for a software from different person we often get the contents changed from the time when we cloned it or forked it so we need to keep on updating the contents of repository. so there are two ways in which you can achieve so:
1. using git pull
2. using rebase
In option 1, You can use the following command:
```bash
git pull upstream main
```
here upstream is the location from where you need to update the content and main is the branch which needs to be pulled.

For option 2, you can use the following command:
```bash
git remote update
git rebase origin/main
```
Rebase is kind of preferred as compared with pull since pull actually is a cobination of git fetch and git merge which actually merge the local changes along with the updates. there can be more explanation on this topic but currently just understand it like this.
<hr>

# Practical Session
Follow the steps in order to create your first pull request.

- Go to the this [link](https://github.com/Cypher-H/Git_Tutorial) and fork the repository
- once You have Forked the Repo clone it into your local pc and keep in mind that you need to copy the url form the forked repo  and run the following command
```bash
cd Desktop
git clone https://github.com/<your username>/Git_Tutorial.git
```
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wlomonccg5fxtkh46i8a.png)

- Create an issue at [here](https://github.com/Cypher-H/Git_Tutorial/issues). you can give any title to your issue.
- Create a branch names "First_PR"
```bash
git branch First_PR
```
- Create a file and write about yourself in that file.The text file should be named as "yourname.txt".windows users can create a text file and save it inside Git_Tutorial.
```bash
cd Git_Tutorial
nano yourname.txt
```
- then create a commit by the following command
```bash
git add yourname.txt
git commit -m "file created"
```
- Push the following code on github
```bash
git push origin First_PR
```
- Create a pull request you will get a link in your command line or terminal.
That's ALL.congratulations you made your first PR!!..<hr>Do share Your feedback with me in comments.You can connect with me on  
 - [linkedin](https://www.linkedin.com/in/honeybhardwaj/)
 - [Github](https://github.com/honeybhardwaj/)