Table of Contents
This tutorial teaches you how to maximize the full potential of GitHub. It presents a broader picture of git and GitHub before getting started with GitHub workflow.
If you already have a basic background of GitHub, why, and when to use it, jump straight into practice in part four. Let's get started.
What is GitHub?
The first step to getting started with GitHub is understanding and distinguishing it from git.
GitHub is a corporation providing code hosting and version control using git. Git, on the other hand, is software that tracks changes in a file using a distributed system.
Distributed means every collaborator has a copy of the project in their local machine. In other words, no central authority stores the files. That means the collaborators can work offline and upload their work to a remote store when connected to the internet.
The key takeaway here is that GitHub is a website that eases collaboration. Git is GitHub's engine, which makes working offline possible.
Why use GitHub?
You probably wonder why you should think about getting started with GitHub in the first place. The three primary children of git are GitHub, GitLab, and Bitbucket. The main reason for the massive growth in GitHub is easy collaboration.
The convenient collaboration springs from comfortable file editing, issue tracking, and the ease of accessing public repositories. Most importantly, you must not pay a coin to enjoy all the awesome features of GitHub.
Who uses GitHub?
The primary aim of creating GitHub was to simplify code sharing among software developers. However, due to the scalability and flexibility of GitHub, anyone who wants to track file changes can use GitHub. So, a better question is, "In what ways can I use GitHub?"
The most familiar ways to apply GitHub are creating software portfolios, blogging, tracking code, scientific and medical research, journaling travel destinations and experiences, and art records.
Here's a simple description of some of the roles of GitHub.
You can use a list of GitHub projects to show your expertise during a job application. With the introduction of GitHub pages, you can run a successful blog or static website on GitHub without worrying about hosting fees, configuring databases, or having HTML and CSS skills.
Several tools such as Jekyll and themes can be crucial during blogging. Also, the researchers can merge their findings on a repository's branch, edit, and solve emerging issues.
Getting started with GitHub in simple steps
There are three keys to unlocking GitHub's full potential: understand git workflow, markdown, and GitHub Workflow. Since git is GitHub's engine, it is crucial to figure out what lies in it before learning GitHub workflow.
Understanding markdown is crucial because markdown is the default file format on GitHub. However, if you lack time to study markdown or you have beat your head with it, but still do not grasp its concept, use tools like the Typora Editor that converts text to markdown.
Lastly, you should understand GitHub workflow because it is the primary target for getting started with GitHub.
Understand git workflow
Git workflow entails three primary stages: working tree, index, and committing. Before you permit git to track changes on files, the changes get packed in the working tree, a place to create or modify files.
Say we create a
history.txt file. The files are untracked until we run the
On initializing a repository, git creates a subdirectory in your project's root called
.git. The subdirectory has all information about the tracked file. Hence, deleting it discards your local repository.
Next, the changes enter the second stage of git workflow: the index, also called staging area. You stage the changes by running any of these commands:
git add <file> git add . git add * git stage <file>
The index is a temporary store, snapshotting the changes until you undo or commit them.
Committing changes means recording the changes in the git database by assigning each commit a unique hash. Before that, git requires you to write a descriptive commit message with the commit command.
git commit -m "Fix (GitHub): Correct the syntax error in app.js"
Now that your changes are part of the history, you can undo or push them to a remote repository like GitHub. Before that, you must have an account with the cloud service provider.
Create a GitHub account
Head over to GitHub's website and click on Sign Up. Fill in your details.
and verify your account by clicking the link sent to your email account.
Once GitHub has verified your account, you can sign in before getting started with GitHub by going through the GitHub workflow. You should also create personal access tokens and generate SSH key pairs to remotely interact with your account.
Getting started with GitHub by going through GitHub workflow
Basic GitHub workflow entails four main stages: creating a repository, branching, committing changes, and handling pull requests. Let's go through each of the steps.
Create your first repository
Unlike in local repository creation, where we instantiate a repo using the init command, GitHub does that for us. Click on New or the plus
+ sign next to your profile picture followed by New repository. Name your repository, then click on Create repository.
A branch is an independent development line. Collaborators open branches, work on them, and then merge the changes with the
Click on the dropdown on the right of the
main branch. Enter the new branch's name in the focused text input. Then click on Create branch: <branch name> from 'main'
Click on Add file followed by Create new file.
Create a file and append some content to it.
Then scroll to the bottom of the page to the commit section. Add a commit message and click on Commit new file.
Handle pull requests
Committing the new branch's changes creates a mismatch between the two (
second_branch) branches. Merging the changes enables us to synchronize the branches. We can do that by creating a pull request.
The mindset to grasp here is working on a large project with many developers.
You have done your role and want to inject the changes into the primary branch of the project. You ask the project manager to accept your changes. Here, we play both roles: of a collaborator and project manager.
Click on Compare & pull request.
Create a merge commit message or go with the latest one from the second branch. Next, add a comment or leave it blank, then click on Create pull request.
Git checks if there are conflicting changes between the two branches. Otherwise, you can proceed, and Merge pull request the changes.
Alternatively, you can close the pull request with a comment. In this case, we are okay with the changes. So, we will go ahead and merge them with the
Git confirms the successful merge.
We can then delete the branch.
Back to the
<> code tab on the repository's navigation bar. We see the merged changes in the main branch.
You have just acquired a fundamental knowledge to getting started with GitHub. Now you understand what GitHub is, why, and how to use it.