The Fundamentals of GitHub

Using VIM to fork, clone, push and pull on GitHub

GitHub is a powerful tool used by millions of developers around the world. GitHub itself is a web-based interface that uses Git, a very powerful open-source version control software that allows developers the ability to fork, clone, push and pull. These concepts are the foundation of GitHub and the reason why developers love using this system.

Today we will be going over these four concepts and by the end, you’ll have a great understanding of each of them and why they are important.

To get started we will need a few things.

  1. GitHub account
  2. A Personal Access Token (see this link for more information)
  3. Access to a CentOS 7 server
  4. Git Installed and Configured on your CLI
  5. * Configure username, email, and “vim” as your default editor

Now that we are signed into GitHub, let’s navigate to the left-hand side of the page where repositories are located and select the one you would like to work on. Note that you will not be able to fork a repository that you own, you must select another user’s repository to do the following steps.

We now have found a repository to work on so let’s start with the first of four concepts, forking. A fork is a copy of a repository that you manage. To begin let’s select the repository we would like to work on. Once selected let’s navigate toward the upper right-hand side of the window and select “Fork”. Afterward, let’s select “create fork”. Congratulations you have now forked a repository!

Now let’s move on to what we will do next with this forked copy of a repository, cloning! Git clone is used to copy an existing Git repository into a new local directory. So in our case, we have just forked an already existing repository and now we want to clone that repository into our local directory. To do this we will need to select the forked version of the repository we just made, then navigate toward the upper right and find the green button labeled “code” and then copy the URL in the dropdown.

Now that we have this let’s hop into our CLI and enter the following command. Do note that the “username”, “repo name” and “<local_repo_path>” will all vary based on your personal information with this repository.

git clone<local_repo_path>

Next up, we will need to navigate our way to our local repository location. To do so we will need to use the following command:

cd <local_repo_path>

Again, your repository path may vary from project to project and most likely will be unique each time.

We can view the files within the repository using the command “‘ls”. Once you have an idea of the file you want to work on use the following command:

vim <file_name>

We are now able to access the file through the text “vim” editor and can make any changes that we see fit. After opening up our file in vim we will press the “i” key to “insert” text into our file. Now that we have made our edits and are happy with our changes we press the escape key to exit “insert” mode. Afterward, type “:wq” and press enter, in this statement, you use the colon to type in the command you wish, then the “w” stands for “write” and the “q” stands for quit. This command allows us to exit our vim editor, while also making sure to save what we wrote in it.

Now we can then check the status of our new repository using the git status command. Here we will see that the file has been successfully modified and we are ready to go. We will then add the modified file by using git add <file_name> then we need to commit the changes to our repository, to do so we will use the command git commit -m. The -m at the end of that command will allow us the opportunity to leave a brief description of the changes we have made so others know what to look for.

Now, we are going to perform a push, the third out of four steps to this process and to do so we will enter the following command git push -u origin main. After entering this command you will be prompted to enter your username and password, just make sure you use the personal access token you received from GitHub for the password. Next, let’s log back into our GitHub account and we will be able to view the file that we just pushed to our repository and perform the last step!

Next up we will perform a pull request to merge our modified repository with our original one. To do this you will go back to the main repository, click “Create Pull Request,” and then create a new pull request. This will send out your modified file to the original file owner and allow them to see what has been changed and any comments you made on the changes. Now, we wait and see whether our request is approved or denied by the original author.

Congratulations! You have performed a fork, clone, push, and pull. This skill set can be very powerful in the tech industry when we are editing files and sending out updates or bug fixes because we allow the original code to continue running and we simply edit a copy of a said file to send in for approval.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dylan Wood

Dylan Wood

AWS Developer Associate | Python | Docker | Kubernetes | Terraform Associate (002) | CI/CD | Linux | Ubuntu |