Sitemap
Charles Black II

Charles Black II

Founder and CEO of Made It Digital. Business | Technology | Personal Growth

Press enter or click to view image in full size

Let’s “Git” It!

7 min readDec 4, 2022

--

A newbie’s guide to “Git.” Forking, Cloning, Editing, Pulling, Merging, and Pushing a GitHub file.

Prerequisites:

  • Basic knowledge of Linux Commands
  • Basic knowledge of Vim Commands
  • GitHub Account
  • GitHub Personal Access Token
  • Access to a cloud server
  • Access to terminal with Git Installed

Git/GitHub Terminology:

  • Repository (Repo): a folder where all files and their version histories are stored
  • Branch: A workspace where you can make changes that won’t affect the live site
  • Fork: A copy or clone of a repo. Allows you to freely experiment with code without affecting the original code. (Great way to use someone’s project as a starting point).
  • Commits: Saved Changes
  • Pull Requests: A way to notify people on your team that you have completed some code and would like their permission to add it to the main file.
  • Merge: Takes code changes from one branch and incorporates them into another.
  • Push: If you change something locally, a push sends your committed changes to a remote repository on GitHub
  • Fetch: process of retrieving a copy of the latest changes from an online repo without committing them.
  • Pull: Process of retrieving a copy of latest changes from an online repo, but the changes are committed.

For starters, lets cover the basics. What is Git? Git is one of the most commonly used version control systems. It’s a free and open source distribution system that tracks your changes you make to files, so you have a record of what has been done. It’s a great tool for collaboration, as it allows for changes by multiple people to all be merged into one source.

What is GitHub? GitHub is a cloud-based Git repository that helps developers store, manage, track, and control changes to their code. GitHub is popular for coders, because it allows for real-time collaboration among developers. It’s commonly used to host open-source projects. Git is the version control system itself, while GitHub allows you to store projects, collaborate, and host service for Git repositories. Projects on GitHub can be accessed by using the Git command-line interface. Below is a step by step tutorial covering the basics of source version control.

In this tutorial, you have been tasked to edit and make changes to an existing repository (repo), without disrupting the repo you currently have in production. The steps below will demonstrate how you can fork a personal copy, edit, and send your changes to the team for review.

Step 1: Fork a Repository

A fork is a copy of a repository that allows you to freely experiment and make changes without affecting the master project. On your Github profile, in the top right hand corner, there is an icon labeled “Fork.” Click the button

Press enter or click to view image in full size

Pretty easy! You have just created a copy of the repository. The next step is making a directory for your repository in your local terminal.

Step 2: Make a Directory

mkdir <create directory name here>

For this tutorial, we will make the directory cbeezy4. See command below.

mkdir cbeezy4

After making the cbeezy4 directory, we need to run the cd command to change the current working directory to the given directory.

cd cbeezy4

The cbeezy4 directory you just created will not have any files listed yet. Run an “ls” command to check. Once we clone the forked repository, we will place files there.

Step 3: Clone the Forked Repository

The original repository we created in Step 1 exist only in your GitHub account. Now, we need to create a local copy of the repo we forked into your local computer and sync between the two. This is called cloning. On the right side of dashboard, there is a green button labeled “Code.” Once you click the button, you will see an HTTPS clone address. Copy the address. See example below.

Press enter or click to view image in full size

Go back to your local terminal and run the following command to create a clone:

Git clone <HTTPS URL you copied>

Trust but verify: Your cbeezy4 repository is no longer empty. If you run an “ls” command in the cbeezy4 directory, you should see the repository you created. In this tutorial, its called “LevelUpTeam.” See screenshot below.

Press enter or click to view image in full size

Now that you have successfully cloned the levelupteam repo, you can now edit locally. In order to edit the repository, you will a text editor called Vim.

Get Charles Black II’s stories in your inbox

Join Medium for free to get updates from this writer.

Step 4: Vim Editor

There will be files and folders in the repository you cloned (LevelUpTeam). In order to check the files, you will need to change directories and run the “ls” command to list the files.

Press enter or click to view image in full size

This example has a directory named “badges” and many files (linux.sh, README.md and README.md.LUIT). For the purposes of this tutorial, we will select and edit the linux.sh file.

vim linux.sh

You are now in your Vim editor and can make the necessary changes. Once changes are implemented, save and exit the file. Ensure your not in action mode by pressing the “Esc” key. Save and exit by typing “:wq” and press Enter. To verify your changes, use the following command:

git status 
Press enter or click to view image in full size

The screen shot shows that the linux.sh file was modified, but changes have not yet been committed.

Step 5: Commit the File

The git command is one of the primary functions of Git, and used to create a snapshot of the staged changes along a timeline of a Git project history. When you commit a file, Git requires that you insert a brief message with your commit in order to let the other collaborators know what you changed.

  • -m option is used to state the message.
  • -a option is used to add your changed files to the staging area.

To commit the changes you made to linux.sh, run the following command:

git commit -a -m "comment describing changes made"

Your terminal will display the commit comment and how many files were changed, and how they were changed via insertions/deletions etc.. See example below.

Press enter or click to view image in full size

You now have changes incorporated to your cloned repo. Now, it’s time to send those changes back to GitHub. We will use the push command to achieve this.

Step 6: Push Files Back to GitHub

Run the following command in order to push commits back to GitHub.

git push origin <Name of remote>

After entering the command above, you will be asked to enter your GitHub username and password.

  • Note: GitHub no longer accepts account password for authentication. You will need to create a personal access token to use in place of your password.

The “How To” guide for creating a GitHub personal access token: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

*Instead of using your account username and password for authentication, you will need to use your personal access token you created. It’s listed as a prerequisite. Use your personal access token when prompted for your GitHub password.

Press enter or click to view image in full size

After entering the personal access token, your will be prompted with username and password. Use the personal access token and your commits will be pushed. See example below.

Press enter or click to view image in full size

Pull up your GitHub account and select the appropriate repository you’ve been working with, and perform a refresh. You should be able to see your commit with the comment you made.

Press enter or click to view image in full size

Step 7: Pull and Merge

Pull requests let you tell others about the changes you’ve pushed in a repository in GitHub. Once a pull request is open, it notifies the team your project changes are ready for review and merge. On the GitHub dashboard, locate the “Pull Requests” button and click it.

Click the green “New Pull Request” button to the right

Press enter or click to view image in full size

Finally, click the green “View Pull Request” button

Press enter or click to view image in full size

Once the Pull Request has been approved, you will be able to compare differences and share them with the original owner. Congratulations, you have successfully forked a file, made edits, and pushed changes back to the main GitHub repository!

--

--

Charles Black II
Charles Black II

Written by Charles Black II

Founder and CEO of Made It Digital. Business | Technology | Personal Growth