What is GitHub and What Is It Used For?

readTime

7 min

What is GitHub and What Is It Used For?

GitHub is an online platform designed for hosting and managing source code for various projects developed by programmers. It is a place where developers can store their projects online, collaborate with others, and track changes in the code.

GitHub is based on a version control system called Git, which allows tracking the history of changes in the code, reverting to previous versions, and working on different versions of a project simultaneously.

Example of Using GitHub

Imagine you're building a website and want to collaborate with a colleague. Here’s how you can utilize GitHub for this project:

  1. Create an Account on GitHub: First, sign up for an account at GitHub.com.

  2. Create a New Repository: Next, you create a new repository (repo) to store the files for your project. A repository is essentially a folder that contains all project files and their version history.

    plaintext
    MyWebsiteProject
    ├── index.html
    ├── style.css
    └── script.js
    
  3. Add Files to the Repository: You can add your project files to the repository, such as your index.html file with the initial website code.

  4. Commit and Push: After adding files, you save the changes to your local repository (using git commit) and push them to the GitHub server (git push).

    bash
    git add index.html
    git commit -m "Add index.html file"
    git push origin main
    
  5. Collaborate with Others: Your colleague can clone your repository (copy it entirely with its entire history) to their computer, make changes, and send them back to GitHub. You both can track who made changes, when, and what changes were made.

    bash
    git clone https://github.com/your-username/MyWebsiteProject.git
    
  6. Pull Request: If your colleague makes significant changes, they can create a pull request, asking to merge their changes with the main project. You can review the changes, discuss them, and decide whether to accept them.

Benefits of Using GitHub

  • Versioning: Track all changes in the project.
  • Collaboration: Easily collaborate with team members, whether you’re working remotely or in the same office.
  • Security: Keep your code backed up in the cloud.
  • Community: Collaborate with developers from around the world, use open-source code, and share your projects.

What is Git?

Git is a version control tool that enables programmers to track changes in files, revert to previous versions, and collaborate on projects with others. With Git, you always know who made changes to the code and when, which is particularly useful when working in a team.

How Does Git Work in Practice?

Imagine you’re writing a book. Every day you add new chapters and correct mistakes. Instead of saving new file versions with different names (e.g., book_version1.doc, book_version2.doc), you can use Git to track changes in a more organized way.

  1. Initialize a Git Repository: Start by creating a repository, which is a special folder where Git will track changes.

    bash
    git init
    
  2. Add Files to Track: Add your files (e.g., book.txt) to the repository so Git can start tracking them.

    bash
    git add book.txt
    
  3. Commit: Save the current state of your files in the repository. A commit is like saving a version of your file with a note about what has changed.

    bash
    git commit -m "Add first chapter"
    
  4. Make More Changes: Continue writing your book, adding new chapters, fixing mistakes, etc.

  5. Another Commit: Save the updated state with a description of what you changed.

    bash
    git commit -m "Add second chapter"
    
  6. View Change History: You can review the history of all commits to see what changes were made and when.

    bash
    git log
    

Benefits of Using Git

  • Tracking Changes: Always know what changes were made and by whom.
  • Reverting Changes: Easily return to a previous file version if something goes wrong.
  • Team Collaboration: Facilitates teamwork by allowing multiple people to work on the same code without conflicts.
  • Security: The code is safely stored and easily accessible, even if something happens to your computer.

Git is an essential tool for developers that helps maintain project organization and streamline collaboration. Without it, efficient teamwork and code management would be much more difficult.

What is a Git Repository?

A Git repository (often called "repo") is where a project is stored, along with its entire history of changes. It’s a structure of directories and files that allows for version control, change tracking, reverting to previous versions, and team collaboration.

Elements of a Git Repository

  1. Project Files and Folders: The repository contains all the files and folders that make up your project. These can be source code files, documentation, images, etc.

    plaintext
    /my_project
    ├── .git
    ├── index.html
    ├── style.css
    └── script.js
    
  2. The .git Folder: This hidden folder contains all the data Git needs to track changes in the project. It’s the heart of the Git repository, storing the entire change history, metadata, and configuration.

  3. Commits: Each commit is a record of the project’s state at a given moment. It contains information about what changes were made, who made them, and when.

  4. Branches: A repository can have many branches, which allow for parallel work on different features. The main (or master) branch is the main branch, but you can create others to work on new features or bug fixes.

    plaintext
    main
    ├── feature-1
    ├── feature-2
    └── bugfix-123
    

How to Use Git in Practice

  1. Initialize a Repository: Create a new repository in an existing project folder.

    bash
    git init
    
  2. Add Files to the Repository: Add files to be tracked by Git.

    bash
    git add .
    
  3. Commit Changes: Create a commit to save the current project state.

    bash
    git commit -m "Initial commit"
    
  4. Create a Branch: Create a new branch to work on a new feature.

    bash
    git checkout -b feature-new-function
    
  5. Work in the New Branch: Make changes and save them in the new branch.

    bash
    git add .
    git commit -m "Add new function"
    
  6. Merge Branches: After finishing work on a new feature, merge it with the main branch.

    bash
    git checkout main
    git merge feature-new-function
    

Git vs. GitHub - Main Differences and Uses

Git and GitHub are two different but closely related tools that are often used together by developers. Here’s a simple explanation of what they are and how they differ:

Git

Git is a version control tool that operates locally on your computer. It allows you to track changes in your code, revert to previous versions, work on different versions of a project simultaneously, and collaborate with other developers. Most Git operations don’t require an Internet connection.

Key Features of Git:

  • Change Tracking: Git tracks which changes were made to files and by whom.
  • Commit: Saves the current state of the project with a comment describing the changes.
  • Branching: Creating branches allows for parallel work on different versions of the project.
  • Merging: Merging branches allows you to combine changes from different project versions.

GitHub

GitHub is an online platform for hosting Git repositories. It allows you to store your Git repositories in the cloud, share them with others, collaborate with other developers, and use project management tools.

Key Features of GitHub:

  • Repository Hosting: Store Git repositories online, accessible from anywhere.
  • Collaboration: Work on code with other developers, regardless of location.
  • Pull Requests: Propose changes to a project and request that they be merged.
  • Issues: Track tasks, bugs, and suggestions related to a project.
  • Continuous Integration/Deployment (CI/CD): Automate code testing and deployment.

Summary

  • Git is a version control tool that works locally. It enables tracking code changes, creating branches, reverting changes, and more.
  • GitHub is an online platform for hosting Git repositories, collaborating on code, reviewing changes, and managing projects.

Using Git on your computer allows you to track code changes locally. When you’re ready, you can push your changes to GitHub to share them or work on them remotely with others.


By using GitHub, developers can collaborate on projects more efficiently, store their code securely in the cloud, and benefit from powerful tools for managing, testing, and deploying their projects.

authorImg

Witek Pruchnicki

I passionately share knowledge about programming and more in various ways.