GitHub Basics

Jesmine Gandhi
Nerd For Tech
Published in
5 min readMar 10, 2022

--

Fork, Clone, Commit, Push, Pull & Edit

What is GitHub

GitHub is a for-profit company that offers a cloud-based Git repository hosting service. Essentially, it makes it a lot easier for individuals and teams to use Git for version control and collaboration.

Additionally, anyone can sign up and host a public code repository for free, which makes GitHub especially popular with open-source projects.

This will be a step by step on “how to” install git, configure git and fork a repository to your local machine. The local repository is where you can make your contributions. From there we will push it back up to GitHub and submit a pull request in order to add our changes to the overall project.

Prerequisites

We are going to achieve the above objective using the following:

  • CentOS7 server
  • vim (text editor)
  • a GitHub account
  • a terminal (mac Terminal or Windows Power-shell)

Step 1: Update your server and Install Git on your CLI

First step should always be to update your server. While updating packages, yum will ensure that all dependencies are satisfied. Use the below command to ensure that.

sudo yum update

Now, install Git onto your CentOS7 server. Use this command to achieve that.

sudo yum install git

Step 2: Setup Configurations for Git

You need to set up your identity so the project owner knows who is submitting their share of work to the projects. You can do that by entering in these commands:

git config --global user.name "User Name"
git config --global user.email "email"

The above commands will establish your username and email address.

Step 3: Fork the Repository

Forking a repository allows you to freely experiment with changes without affecting the original project. Visit the project page for the repository that you would like to fork on GitHub. Click the fork icon on your GitHub page.

Step 4: Clone the forked repo to your local server environment

Clone a forked repository with GitHub Desktop to create a local repository on your computer. You can create a local copy of any repository on GitHub that you have access to by cloning the repository. Clone the repository to your local machine by clicking “Code” on your GitHub profile screen. You will see a link under HTTPS, copy that link.

Now, in your CLI environment, make a new directory where you can put the clone. Inside of that directory, enter the git clone command (Paste https link you copied from your GitHub page behind the command). This command will create a directory with your project files inside. You will see “done” when it is complete

mkdir <directory name>
cd <directory you just created>
git clone <url>

Step 5: Make your edits

This is where we make our contributions and edit files as per need.

Vim is a highly configurable text editor built to enable efficient text editing. To use Vim properly for this project, change your current directory to the directory that has the file you would like to edit with in. Enter this command:

vim <filename>

In the insert mode (press i key), enter the changes to the file. After making necessary changes to the file, press the esc key to come out of insert mode. Now press :wq to save and quit!

Step 6: Add and commit the file to your local repo

After you make necessary changes to the file, add the file to your local repo using the below command.

git add <filename>

This command tells Git that you want to include updates to a particular file in the next commit.

Next we need to commit our changes, or start the process of getting the changes back up to GitHub.

git commit -m "Comment about your contribution"

Step 7: Send the commits from your local repo to the remote repo

Pushing is how you transfer commits from your local repository to a remote repo.

There are a few extra steps needed for this. The first little step is set up access to GitHub. Go to your settings in GitHub, then go to “Developer Settings” at the very bottom and click on “Personal Access Tokens”.

Next, click on “Generate new token”. Provide a descriptive name for your token and make your selections as shown below!

Click on “Generate Token” and do copy this token to your clip board or save it to your notes.

Now go to your Linux environment and push the changes to your remote repository by using the following command and enter the token when prompted.

git push -u origin main

Step 8: Send a pull request

A pull request is an event in Git where a contributor asks a maintainer/developer of a Git repository to review code they want to merge into a project.

To do this, go to the pull requests tab and click on “New pull request”.

Enter the description for your contributions to the project & then click on “Create pull request”. And that's it!!

Congratulations!! You have successfully made your contributions to the project on GitHub.

--

--

Jesmine Gandhi
Nerd For Tech

DevOps Engineer | AWS Certified Developer Associate | Docker | Terraform