How to Install Git and Clone a GitHub Repository

Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

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.

  1. Install:

    sudo apt-get update
    sudo apt-get install git -y
    
  2. Configure the username, replace First Last:

    git config --global user.name "First Last"
    
  3. 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.

  1. 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.

    GitHub homepage search.

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

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

    GitHub clone clipboard.

  4. 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
    
  5. Change directories to the new ~/test-repo-789 directory:

    cd ~/test-repo-789/
    
  6. 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.

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

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

    GitHub username icon.

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

  4. 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.

    GitHub Fork Button.

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.

  1. From the ~/test-repo-789 directory, create and checkout a new branch:

    git checkout -b newbranch
    
  2. Create a project directory:

    mkdir project
    
  3. Create sample files:

    touch repoTest1.js repoTest2.htm project/prjtTest1.js project/prjtTest1.htm
    
  4. Check the status of the Git project, with the git status command:

    git status
    
    # On branch newbranch
    # Untracked files:
    #   (use "git add <file>..." to include in what will be committed)
    #
    #       project/
    #       repoTest1.js
    #       repoTest2.htm
    nothing added to commit but untracked files present (use "git add" to track)
    
  5. Add all the files in ~/test-repo-789 to the Git staging area:

    git add .
    
    Note
    To add only one file, replace the period above with the full directory path and filename.
  6. Check the status again with git status, then commit the files to the Git project:

     git commit -m "Test files for test-repo-789 fork"
    
  7. Push the new files to the forked repo on your new GitHub account. Replace SampleUser1234 below with your own GitHub username, and replace the repo name with the appropriate repo name if different:

    git push https://github.com/SampleUser1234/test-repo-789.git newbranch
    
    Note
    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.

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

    GitHub username icon.

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

    GitHub popular repositories.

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

    GitHub branches.

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

    GitHub branches.

  5. Check that the branch filters are set correctly.

  6. Select the “Create pull request” button.

    GitHub branch filters.

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.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.