Getting Started with Github Commits, Merging and Pull Request


GitHub is a web hosted collaboration and version control solution that is opened sourced. The main purpose of this tool is to allow for developer teams to collaborate on projects virtually.

Developers and bloggers, typically use this tool to collaborate on community projects and companies use it in the same manner for corporate tech initiatives.

To use this tool you do not need to write any code, all you will need, is a internet connection and a understanding of the concepts of pull request, branches, commits and repositories. With a understanding of these concepts you can create projects to be shared with the community. You can also work on other projects that have been shared by the GitHub community.

In the steps below we will walk through the 4 GitHub concepts referenced above. Before you can begin this process you will need to go to GitHub and setup a account.

Repositories

A GitHub repositories is like a file system folder, it is container used to store and organize files that relate to single project/solution. A repository and hold any file types that are need for a project or solution to run. This include README, image, video, excel, txt or any other file that may be need.

Note: It is a best practice to include a README file in each repository that provide information such as a project description and any critical information needed to setup or execute the project.

Create Repository
  1. Select New repository
  2. Name the repository
  3. Add a short description of the repository contents
  4. Initialize this repository with a README

Github img2
Select New repository
Github img3
Name, add a short description and Initialize the README file
Github img5
Type the new branch name.
Click Create and you are done. The new respoistory is ready for use.
A few things to note when creating a repository.

  1. You can add a License and this will determine how the code you upload should be used. In this case I used the MIT License are it is the least restrictive.
  2. Directories can be Public or Private and as the names imply the public directories can be seen by anyone on GitHub and the private directories are not access to the public.

Now that we have create a repository we can talk about Branching.

Branching

Branching allow you to work on different version of your repositories at the same time without changing the master copy. This is really helpful when you want to make changes to the code base without modifying your working code base.

When you create a repository the master branch is created and is known as the definitive code branch. A branch is a snapshot of the master repository and is used to make change which can then be committed to the master branch.

Create a branch

Github img6
Git-Branch-Img
Now that we have created a new dev branch we have two copies of our repositories and we can make changes in the dev branch without affecting the master branch.
In the dev branch you will make code changes test them and once you verify the changes are complete you can commit the changes to the master branch. Once code is comment to the master branch all subsequent pulls from this branch will have the newly committed changes.

Commits

When you are working with GitHub commits is the equivalent of a file save operation in a word doc. It save the changes and allows for you a add a message to be stored with the associate commit. This is helpful to document why changes are being made to the code.
Note: It is a good practice to add a messages with changes this will be very helpful when it comes to debugging and rolling back code changes.

Commit Changes
  1. In the dev code view select “Upload Files”
  2. Browse and select file for upload
  3. Add a message for the change being committed
  4. Select Commit Changes

GitHub img8
You can now see the committed changed file in the code view. Now that we have created a repository, made a branch of that repository and made changes to the branch we can move on to Pull Request. A Pull Request is what unlocks the power of GitHub.

Pull Request

A pull request is when you make a request to have your code reviewed and merged in the main(master) branch of code. When you make a pull request you will see a comparison that will highlight the difference in the code compared to the master branch.
After you make a commit that commit is eligible to make a pull request.

Open a Pull Request
  1. Select Pull request tab
  2. Click “New Pull Request “
  3. Select the compare branch
  4. Click View pull Request
  5. Verify information and add a comment
  6. Click Merge pull request
  7. Confrim Merge

GitHub Img 9
Git Img10
Github Img11
We have completed the setup and basic use of GitHub. This post was design to help you get started using GitHub. I hope you found this post informational.

Please leave comment and feed back below.


Leave a Reply