Onboarding Documentation for Git and GitHub

Welcome to Git and Github at ChaiCode Cohort!

In this document you will know about how Git and Github work in our company. The purpose of providing this documentation to every new employee is to maintain the consistency and efficiency of the company rules. Please read it carefully and follow all the instructions.

As you know Git and Github are one of the most important tools in life of developers. These tools provides us a collaborative platform to save and share our codes with other developers. Not using this tool properly or Lack of knowledge about these tools may create unwanted issues so please pay attention to this documentation to avoid severe damages to the company and your career as well.

What is Git?

Git is a Version Control System (VCS) that is used to work on big projects with multiple developers. With the help of Git, a group of engineers can work together on same project. They can save their codes with a commit message and it becomes usable as a checkpoint to make any edit in the code. It helps you to develop software with more efficiency and speed.

What is GitHub?

Github is a place where all the codes are saved from different developers. It is saved as repositories. Repositories are nothing more than folders but in tech slang. Developers can push or pull the codes from these repositories and start working on that. After finishing up their work they can push it again in the repo with a commit message.

Installation and Setup:

Step 1: Go to https://git-scm.com/downloads

Step 2: Download for your corresponding Operating System

Step 3: Run the installer and the installation will begin.

Step 4: After installation run these command to check if the Git is installed properly

git --version

Configure Git with Username and Email:

  1. Configure your Name:

     git config --global user.name "Your Name"
    
  2. Configure your Email Id:

     git config --global user.email "your.email@example.com"
    
  3. To check your settings, Run;

     git config --list
    

Cloning the ChaiCode Repository:

Cloning in Git means coping an existing file from a remote machine to your local machine. This is useful because whenever you have to work on a project that is already hosted then you can pull that from here.

Step-by-Step Instructions to Clone a GitHub Repository:

  1. Go to the repository page on GitHub.

  2. Click the CODE button and copy the repository’s URL.

  3. Open your VS Code and go to the folder where you want to store the repository.

  4. Open the terminal in VS Code and run the following command:

     git clone https://github.com/ChaiCode/example-repo.git
    
  5. For moving into the cloned repository use the cd command:

     cd <directory-name>
    

Basic Git Commands:

  • git status

    This command is used to check current status of the repository. There are three types of status: MODIFIED, ADDED, STAGED

  • git add

    This command stages a specific file for committing in git repo.

  • git commit -m "message"

    This command saves your changes with a message about what was done.

  • git push

    This command is used to push commits to the remotes repository.

  • git pull

    This command is used to fetch and merge changes from a remote repository.

  • git log

    This command is used to view the commit history.

Commit Message Rules:

  • Use the present tense ("Add feature" not "Added feature").

  • Capitalize the first letter.

  • Keep the message short (50 characters or less).

  • Use prefixes like fix:, feat:, chore:, docs: for categorization.

  • Example:

      feat: Add tea selection feature fix: Resolve login issue 
      for tea enthusiasts docs: Update README with chai varieties
    

Branching Workflow:

  • Main Branch (Stable Version)

    In this branch all the codes are production ready. They are well tested and reviewed.

  • Development Branch (Ongoing work)

    In this branch ongoing development codes are pushed. They are yet to be tested and may have bugs also.

  • Feature Branches (New Feature Development)

    This branch is used for all the different kinds of features e.g. login page, notification system or forms. Once they are ready and tested then they can be added in Development Branch.

Steps for Working with Branches:

  • Create New Feature Branch:

        git branch <branch_name>
        git checkout <branch_name>
    
  • Switch to the Development Branch:

      git checkout development
    
  • Merge the Feature Branch:

      git merge feature/<feature-name>
    

Pull Requests (PR):

Steps to Create a Pull Request:

  1. Push your branch to the remote repository:

     Copygit push origin <branch_name>
    
  2. Go to the repository on GitHub and navigate to the Pull Requests tab.

  3. Click New Pull Request.

  4. Select the base branch (e.g., development) and compare it with your branch.

  5. Review the changes and click Create Pull Request.

Best Practices:

To maintain high code standards and to avoid all the unnecessary problems follow these best practices:

  1. Regular Commits

    • Make small and frequent commits to track progress effectively

    • Avoid committing large chunk of codes at once

  2. Descriptive Commit Messages

    • Always write clear commit messages

    • Messages should explain what changes are made

  3. Pulling Updates Regularly

    • Regularly update your local branch by pulling changes

    • It will make your branch up-to-date and minimize merge conflicts