ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

GitHub Essentials

Share on whatsapp
Share on facebook
Share on twitter
Share on linkedin

Every programmer at point in time must have heard about GitHub, maybe from a friend, colleague or during a tutorial. GitHub is basic a tool that makes it easier for programmers to collaborate on projects and store projects online. GitHub works with Git. In this article I will talk about the basics with getting started with GitHub.

Before Starting this article ensure Git is installed on your system and you have a basic understanding of It. You can check my blog post on Git.

 

Creating your GitHub account

Creating a GitHub account is as simple as filling an online form. All you have to do is type in your username, email and then password. You will later have to verify your email. There will be an option to select a subscription plan, the free offer by GitHub is very generous and suitable for most programmer; this is the plan I recommend.

There will also be a section to pick your interests and write about your self. This aspect is option and can be easily skipped

 

Setting Up Your First Repository

To setup a repository click on the dropdown beside the ‘+’ icon at the top right of the screen. Then select ‘New Repository’. You will be directed to a page where you will fill out the repository details. Enter the repository name and then set the visibility to either public or private. Click on Create repository. Congratulations you have created your first repository.

 

Pushing Code to your repository

To do this navigate to the folder where the projects code is with command prompt or any terminal of your choice  ( a shortcut for windows users, in the address bar in file explorer type ‘cmd’ and press enter ). A command prompt terminal will be open in your current directory. Then run the following commands

git init
git add .
git commit -m 'message about the commit goes here'
git remote add origin master https://github.com/<your-username>/<your-repo-name>.git
git push -u origin master

Let me explain what all these commands do. The first line initializes a git repository in your current directory. The second line stages ( tracks them for changes ) all the files in the current folder. The third line saves all the changes you made to your local  repository and adds a message to explain it ( commits the changes ). The fourth line associates the local git repository with your GitHub repository. While the last line pushes all commits to your GitHub repository.

 

Updating Your Repository

To update your GitHub repository with your new files simply run the following commands in a terminal window in your working directory.

git add .
git commit -m 'message about the commit goes here'
git push origin master

 

Updating Your Local Repository

If you are working with a team on a project, other members will make changes to the GitHub repository; to get these changes on your PC run the following command

git pull origin master

 

Cloning A Repository

This is copying all the files from a repository to your computer. This is different from downloading the repository because, when you clone a repository the remote URL and log is history is already setup. To clone a repository you first need the repository URL. This can be gotten from the ‘clone or download’ button on the repositories page

After the URL is copied run the following commands in the folder where you want to clone the repository to

git init
git clone <github-repository-link>

To clone a particular branch ( this term is explained later on ) in a repository run the below command instead

git init 
git clone -b <branch-name> <github-repository-link>

 

Branching and Merging

When working on a project you can have different versions of your app or an experimental version. Branches makes working with these different versions in a repository easier. The general rule of thumb is that your main active branch is called master ( GitHub just recently changed it to main ). You can merger other branches with master, for example you have just completed a new version on another branch, you can merge it with the master branch.

To create a new branch run

git checkout -b <branch-name>

If you want to check the active branch run this command an ‘*’ will be  in front  of the active branch

git branch

 

Pull Request

We create a pull request to notify the project owner (or the team leader) that we want to implement some changes from our custom branch to the main master branch. To create a pull request we click the pull request button and then we fill a form explaining the details of the pull request. The pull request may take some time to be approved by the team leader and you he may send the request back for a review.

 

Forking A Repository

Forking a repository is useful when you want to make a contribution to a popular project, a third party library or use another project as the starting point for yours. This is a very popular aspect of working with open-source projects. To fork a project simply means to create a copy of the repository and the copy will be owned by you. To do this simply click the fork button in the repository page.

When the repository has been forked you can make the necessary changes, then you can open a pull request to merge your forked repository with the original one. The process is the same as explained earlier in this article.

Note when contributing to open source projects ensure you follow the guidelines made by the developer and leave a detailed explanation of the changes you made in the pull request.

 

GitHub is a vey powerful tool and you should use it in your next project.

Some Extra Resources:

ADVERTISEMENT

Other Blog Posts

University Education ?

University education is a very controversial topic in our society today. Many people say it is not important while some are a not in support

Read More

Gotham Full Review

Gotham is an action crime television series produced by Warner Bros. Television. The show ran for 5 seasons from 2014 – 2019 with 100 episodes;

Read More