How to Install Git and Clone a GitHub Repository

GitHub is a website that allows collaboration between developers using the Git version control system. With Git and GitHub, programmers from across the world can share ideas and code in an organized and up-to-date process.

Install and Configure Git

The directions below are for Debian or Ubuntu. For installation on Mac, Windows, or other Linux distributions, find instructions in the Git Source Control Management guide. While that guide focuses on Git, this guide focuses more on Git with GitHub.

Install:

sudo apt-get update
sudo apt-get install git -y

Configure the username, replace First Last:

git config --global user.name "First Last"

Configure the email, replace example@example.com:

git config --global user.email "example@example.com"

Now that Git has been installed, refer to the image below for help with using Git and GitHub together.

Clone a GitHub Test Repository

A repository, or repo, is a Git project. For tutorial purposes, there is a test repository setup on GitHub, which is listed below.

Go to the GitHub homepage. At the top, search for test-repo-789. If you would like to contribute to Linode’s guides, search for linode docs.

Select test-repo-789, it should be the first result, listed as NwayNway/test-repo-789.

Copy the “HTTPS clone URL” link using the clipboard icon at the bottom right of the page’s side-bar, pictured below.

In the Linode terminal from the home directory, use the command git clone, then paste the link from your clipboard, or copy the command and link from below:

git clone https://github.com/NwayNway/test-repo-789.git

Change directories to the new ~/test-repo-789 directory:

cd ~/test-repo-789/

To ensure that your master branch is up-to-date, use the pull command:

git pull https://github.com/NwayNway/test-repo-789.git master

Create a GitHub Account and Fork the Test Repo

To share new files or file revisions, you’ll need a GitHub account and a project fork. A fork is a copy of a repo held on your GitHub account.

Create a username on GitHub. At the “Welcome to GitHub” page, select the green, “Finish sign up” button at the bottom.

Select your username at the top right of the page, pictured below, which links to your profile.

To fork test-repo-789, use the search bar at the top left of the page. Search for test-repo-789.

After you select NwayNway/test-repo-789, fork the repo using the “Fork” button on the top right of the page. The “Fork” button is under the username icon pictured in step 2 above.

You now have a copy of the repo on your GitHub account. Next, return to the terminal of the development Linode.

Push to the Forked Repo

Create files on the development Linode and push them to the forked repository on GitHub.

If you’ve configure two-factor authorization (2FA) on this account, you will need to push over SSH. See GitHub’s guide on Generating SSH Keys.

Create a Pull Request Against the Original, Previously Cloned Repo

So far, Git was installed on a development Linode, a repo project was cloned to that Linode, a GitHub username was created, and a repo fork was copied to the GitHub user account. The final step is to ask the original repo project to accept the new revisions or sample files. This final process is called a pull request.

From the GitHub browser window, select your username from the top right of the page, pictured below.

At your GitHub profile, select the test-repo-789 in the center of the page, pictured below.

At the test-repo-789 page, select “branches”.

Under “Your branches”, select “New pull request”.

Check that the branch filters are set correctly.

Select the “Create pull request” button.

Congratulations, you have used Git and GitHub for file sharing and version control. There are still many Git commands to learn, but you are off to a great start.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.