What is GitHub?

GitHub is a platform for version control and collaboration. It lets you and others work together on projects from anywhere. GitHub is built on top of Git, which is an open-source version control system created by Linus Torvalds.

Key Concepts

  • Git: A version control system to track changes in files and coordinate work on those files among multiple people.
  • Repository (Repo): A project folder that Git tracks. It contains all project files and the entire revision history.

A web-based interface that uses Git for version control. It also provides access control and several collaboration features, such as bug tracking, feature requests, task management, and wikis.

Basic Terminology

  • Commit: A record of changes made to the files in a repository.
  • Branch: A parallel version of the repository. It allows you to work on different versions of a project simultaneously.
  • Merge: Combining changes from different branches into one branch.
  • Pull Request (PR): A method for submitting contributions to a project. You make changes in a branch, push them to GitHub, and then open a pull request.
  • Clone: A copy of a repository that lives on your computer instead of on a website’s server.
  • Fork: A personal copy of someone else’s repository that lives on your GitHub account.

Getting Started with GitHub

  1. Create a GitHub Account:
    • Go to GitHub and sign up for an account.
  2. Install Git:
  3. Basic Git Commands:
    • git init: Initialize a new Git repository.
    • git clone [url]: Clone a repository into a new directory.
    • git add [file]: Add a file to the staging area.
    • git commit -m “message”: Commit changes with a message.
    • git push: Push changes to the remote repository.
    • git pull: Fetch and merge changes from the remote repository.

Creating Your First Repository

  1. On GitHub:
    • Click on the “+” sign in the upper-right corner and select “New repository.”
    • Name your repository and click “Create repository.”
  2. On Your Computer:
    • Open a terminal (Git Bash on Windows).
    • Clone the repository: git clone [your-repo-url]
    • Navigate to the repository folder: cd [repo-name]
    • Create a new file: echo “# My First Repo” >> README.md
    • Add the file: git add README.md
    • Commit the file: git commit -m “Add README”
    • Push the changes: git push origin main

Using GitHub for Collaboration

  1. Forking a Repository:
    • Go to the repository you want to fork.
    • Click the “Fork” button in the upper right corner.
  2. Making Changes:
    • Clone the forked repository to your local machine.
    • Create a new branch: git checkout -b my-feature-branch
    • Make your changes and commit them.
    • Push the changes: git push origin my-feature-branch
  3. Creating a Pull Request:
    • Go to your forked repository on GitHub.
    • Click the “New pull request” button.
    • Select the base and compare branches.
    • Click “Create pull request” and add a description.

Additional Resources