Skip to main content

GitHub

GitHub is a web-based Git repository hosting service. It works just like Google Drive, but for code. It allows you to store your code in the cloud and collaborate with others. You can create a repository, add collaborators, and work on the same codebase. GitHub also has a feature called pull requests which allows you to request changes to be merged into the main codebase.

GitHub Repository

A repository is a place where your code is stored, like a folder on your computer but in the cloud. A GitHub repository can be public or private. A Public repository is visible to everyone, while a Private repository is only visible to you and the collaborators you add.

On GitHub repository you can see the past changes made to the codebase, who made them, and when they were made. You can also see the current state of the codebase, the branches, and the pull requests.

GitHub Pull Request

A pull request is a proposal to merge changes from one branch into another, just like a git merge. It allows you to request changes to be merged into the main codebase. You can create a pull request on GitHub by clicking on the New pull request button on the repository page.

The difference between a git merge and a pull request is that a git merge is done locally on your machine, while a pull request is done on GitHub and needs a review or someone to approve the changes.

GitHub Fork

A fork is a copy of a repository, It Allows you to freely experiment with changes without affecting the original project. This also allows you to contribute to a repository that you don't have direct access to. Once you've made changes to your fork, you can create a pull request to propose your changes to the original repository.

Common GitHub Commands

Command Description
git clone <repository_url> Clone a repository to your local machine
git pull Get the latest changes from the remote repository
git push origin <branch_name> Push the committed changes to a remote repository

Setting up GitHub with local Git

Configuring your local Git with GitHub is a one-time process

git config --global user.name "Your name"
git config --global user.email "Your email"

There are two ways you can connect your local Git with GitHub:

Creating the local folder first

  1. Create a new folder on your local machine
  2. Initialize a new Git repository
  3. Add your files to the staging area
  4. Commit your changes
  5. Create a new repository on GitHub (without a README file)
  6. Add the remote repository URL to your local repository
     git remote add origin <repository_url>
    
  7. Push your changes to the remote repository

Creating a repository on GitHub first

  1. Create a new repository on GitHub
  2. Clone the repository to your local machine
     git clone <repository_url>