How to use GitHub

Let's start with GitHub basics

Github

GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere. This tutorial teaches you GitHub essentials like repositories, branches, commits, and pull requests.

What software does GitHub use?

GitHub is a web-based interface that uses Git, the open source version control software that lets multiple people make separate changes to web pages at the same time.

How we can start programming on GitHub?

Step 0: Install git and create a GitHub account.

Step 1: Create a local git repository.

Step 2: Add a new file to the repo.

Step 3: Add a file to the staging environment.

Step 4: Create a commit.

Step 5: Create a new branch.

Most used Git commands

There are hundreds of Git commands, but just a few are used regularly.

1. git config

The git config command is used to set Git configuration values on a global or local project level.

# sets up Git with your name

git config --global user.name "<Your-Full-Name>"

# sets up Git with your email

git config --global user.email "<your-email-address>"

2. git init

The git init command is used to initialize git into your project. The " git init " command creates all of the necessary files and directories for Git to keep track of everything. All of these files are kept in a directory called .git. By default .git folder is hidden on Mac/Linux.

$ git init

3. git status

The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.

$ git status

4. git add

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit.

Syntax to add

  1. Specific file
    $ git add <filename>
    
  2. To add all files
    $ git add .
    

5. git commit

This command saves a log message along with the commit id of the modifications made to the git repository. The modifications are saved in your local repository with git commit.

$ git commit -m  "Type your commit message here"

6. git push

This command pushes the contents of your local repository to the remote repository you’ve added.

$ git push

7. git clone

git clone is primarily used to point to an existing repo and make a clone or copy of that repo in a new directory, at another location.

# Copy the repository link and paste it after git clone command 

$ git clone https://github.com/<repo-url>