Portainer News and Blog

Beginners Guide to Git & GitHub

Written by Hrittik Roy | December 15, 2021

Introduction to Git & GitHub

Hi, I'm Hrittik Roy, a sophomore from Kolkata, India, and the youngest Portainer Advocate. I work at p3r, where I lead content marketing efforts, and in my free time, I like going on long walks or sharing what I know about tech with my colleagues, juniors, and other people I come across the internet.

This post would go through an event where we talk about Git and GitHub with a unique giveaway supported by Portainer, a centralized service delivery platform for containerized apps.

The discussion was mainly on Git, GitHub, Version control system, and Pull-request. It started with a descriptive note where we got the knowledge of the Version-control System. The participant also contributed to a demo repository for a better understanding of Git. Most of the audience were first and second-year students with few professionals who are looking to upskill.

Let's start!

What is Git?

Git is the most commonly used version control system. Git tracks the changes you make to files, so you have a record of what has been done, and you can revert to specific versions should you ever need to. Git also makes collaboration easier, allowing changes by multiple people to all be merged into one source.

Git Basic Terminology

Branch

A branch is a version of the repository that diverges from the main working project. It is an essential feature available in most modern version control systems. A Git project can have more than one branch. We can perform many operations on Git branch-like rename, list, delete, etc.

Main

Main is a naming convention for Git branch. It's a default branch of Git. After cloning a project from a remote server, the resulting local repository contains only a single local branch. This branch is called a "Main" branch. It means that "main" is a repository's "default" branch.

Pull/Pull Request

The term Pull is used to receive data from GitHub. It fetches and merges changes on the remote server to your working directory. The git pull command is used to make a Git pull.

Pull requests are a process for a developer to notify team members that they have completed a feature. Once their feature branch is ready, the developer files a pull request via their remote server account. Pull request announces all the team members that they need to review the code and merge it into the master branch.

Push

The push term refers to upload local repository content to a remote repository. Pushing is an act of transfer commits from your local repository to a remote repository. Pushing is capable of overwriting changes; caution should be taken when pushing.

Repository

In Git, Repository is like a data structure used by VCS to store metadata for a set of files and directories. It contains the collection of the file as well as the history of changes made to those files. Repositories in Git is considered as your project folder. A repository has all the project-related data. Distinct projects have distinct repositories.

What is GitHub?

GitHub is a Git repository hosting service. GitHub also facilitates with many of its features, such as access control and collaboration. It provides a Web-based graphical interface.

Features of GitHub

Some of its significant features are as follows.

  • Collaboration
  • Git repositories hosting
  • Project management
  • Team management
  • Track and assign tasks

Forking A Repository

A fork is a rough copy of a repository. Forking a repository allows you to freely test and debug with changes without affecting the original project. One of the excessive uses of forking is to propose changes for bug fixing. To resolve an issue for a bug that you found, you can:

  • Fork the repository.
  • Make the fix.
  • Forward a pull request to the project owner.

Forking is not a Git function; it is a feature of Git service like GitHub.

How to Fork a Repository?

It is a straight-forward process. Steps for forking the repository are as follows:

  • Login to the GitHub account.
  • Find the GitHub repository which you want to fork.
  • Click the Fork button on the upper right side of the repository's page.

We can't fork our own repository. Only shared repositories can be fork. If someone wants to fork the repository, then he must log in with his account.

Editing Readme File

 

Click the README.md link from the list of files. Click the Edit button. Delete the following text: Delete this line to make a change to the README from Bitbucket. After making your change, click Commit and then Commit again in the dialog.

 

 

 

Pull Requests

Pull requests are a way to discuss changes before merging them into your codebase. Let's say you're managing a project. A developer makes changes on a new branch and would like to merge that branch into the master. They can create a pull request to notify you to review their code. You can discuss the changes, and decide if you want to merge it or not.

Step 1 - To begin a pull request (PR), click the pull request button on the main repository page.

Step 2 - Which repo to update - select your base & head

Next, you need to select which repo you wish to update (the base repo) and which one contains the content you wish to use to update the base (the head repo). In this example, you want to update FORKED_USERNAME/BRANCH-NAME-git with commits in your fork YOUR-USERNAME/BRANCH-NAME-git.

Step 3 - Verify changes

When you compare two repos in a pull request page, GitHub provides an overview of the differences (diffs) between the files. Look over the changes and make sure nothing looks surprising.

Step 4 - Create a pull request

If you add new commits to the Earth Lab repo, the pull request button will be available. Click the green "Create Pull Request" button to submit your pull request.

Step 5 - Describe your pull request using a short title

Give your pull request a title and write a brief description of your changes. When you're done with your message, click "Create Pull Request".

Giveaway

With the end of event closing, the giveaway details were near, which gave free pass to KubeCon Event through KubeCon Virtual Ticket worth $75. The lucky winners were announced based on Pull Request that the participants in the session submitted. And the most awesome part was most of the winners were attending KubeCon for the first time. This makes the event successful for me!

 

Final Thoughts

Conducting an event is a challenging and exciting task on its own. From presentations to participants and sponsors managing everything together is complicated and a person can't manage it all on their own. I hoped this event would help you get accustomed to git and github. After you have learned version control, it's time for deployment. If you want to deploy applications on k8s using GitOps without the complexity of setting argocd/flux up, feel free to try Portainer here.

I would like to thank Portainer for the support and excellent students like Abhishek Kushwaha for helping me with this post and the event.

Curious about what event's next? Feel free to connect with me on Twitter and Linkedin to stay updated.

PS: I maintain a repository where you can find my latest events. Feel free to Star and follow along!

Happy Learning!