Vonage is thrilled to be a Hacktoberfest 2020 partner. We’re no strangers to open source, with our libraries, code snippets, and demos all on GitHub. To fully immerse yourself in the festivities, be sure to check out our Hacktoberfest page for details on all that we have planned!

What Is Git?

How Can I Install Git?

First, check whether you have Git installed on your computer. In your Terminal or Command prompt, type Git --version. If installed, you should see an output similar to what's shown in the image below:

If you don’t have Git installed, please go to git-scm.com for the download and instructions on how to install Git on your Operating System.

Create a Local Repository

This command will create a .git directory. This directory contains the information necessary for your project to be version controlled. It also includes the information about the project's branches, commits, and if you host your git repository remotely, the address for this remote repository. Having all of this information allows you to know which branches you can switch between for different purposes, as well as rolling back to various commits in the history if necessary.

Add Files To the Repository

Again, in the command line, but you can use a text editor or an IDE to create new files to your project.

If you then open your file, you’ll see the text This is the README file for my first Git repository.

Commit Your New Files

As shown in the image above, the first line tells you which branch you’re in, and the second line explains whether you have any unpushed commits. Following this, you’ll see any untracked files which list the files you’ve yet to commit; in this instance, it’s the README.md file.

Now it’s time to add this file to commit it to history.

Branching Out

You can create a new branch by typing the following command:

If you wished to see what branches are available, type: git branch to list the branches you have locally on your machine.

Add New Files To the New Branch

Now commit this change with the following:

Compare Differences Between Primary and New Branch

Check out back into your primary branch with the command: git checkout <primary branch name>.

Now it’s time to have a look at GitHub and hosting your repository remotely.

GitHub

Create a Repository on GitHub

Once created, some options are provided with how to get set up with your repository. As you already have the repository locally, choose the third option below where it says ...or push an existing repository from the command line.

Create a Pull Request

Then, in Github, navigate to your repository, click “Create Pull Request”, and click on your second branch name. You’re taken to a page with a list of changes. These changes show the commits and the files changed. Again, click on the “Create Pull Request” button to be taken to a page with two input boxes.

This part of creating a pull request allows you to describe the changes you wish to be merged into the primary branch. It is good practice to be as descriptive as possible in the description box. This page will allow anyone to understand what the changes are and how they impact the current project.

Once you’re happy with the title, the description, and if you wanted to add anyone to review your pull request. Click the “Create Pull Request” button.

Now you or your co-contributors can review the changes and determine whether they should be merged into the primary branch.

If you are happy to merge this branch, click the “Merge Pull Request” button. You have now merged your changes into the primary branch.
If you go back to your Terminal, make sure you are on the primary branch, then type git pull, you'll see the file you added to the second branch is now in your primary branch!

Conclusion

Following the above steps, you created a GitHub account and a repository on GitHub. You then linked your local repository to your GitHub repository and pushed your branches, changes, and commits to this remote repository.
Next, you created a Pull Request, which highlighted the differences between your two branches, and allowed you to merge the secondary branch into the primary, so that now all changes exist in the primary branch.

With Hacktoberfest just around the corner, there’s no better time to put your Git learnings into practice! We are excited to be a Hacktoberfest partner this year, so you might want to check out some of the Vonage projects while you work towards your PR goal. Happy hacking!

Don’t forget, if you have any questions, advice, or ideas you’d like to share with the community, then please feel free to jump on our Community Slack workspace, or pop a reply below 👇. I’d love to hear back from anyone that has implemented this tutorial and how your project works.

Developer content from the team at Vonage, including posts on our Java, Node.js, Python, DotNet, Ruby and Go SDKs