Welcome to Git and GitHub at ChaiCode Cohort!

Welcome to Git and GitHub at ChaiCode Cohort!

A Simple Guide to Getting Started with Git and GitHub

Introduction

Welcome to ChaiCode Cohort Company! This documentation is your go-to guide for using Git and GitHub in our organization. Git and GitHub are essential tools for managing code, collaborating with other developers on code or projects and effectively working with other developers or teams.

Basic of Git and GitHub

What is Git ?

Git is a tool that helps you keep track of changes to your code. It also allows multiple people to work on the same project at the same time without overwriting each other’s code.

What is GitHub ?

GitHub is a website where we store our code. It helps teams work together, review changes and organize tasks.

Installation and Setup

Step 1 :- Install Git

Windows

  1. Download Git (Windows version) from git.scm.com

  2. Open the downloaded Windows version and install it. IMPORTANT :- “Choose your default editor used by Git” page, select your code editor i.e. VS Code Editor. Unless otherwise told, use the default settings.

    (And if you get stuck and don’t know how to proceed go here to see what to do next)

  3. Open the Command Prompt and type this command to check whether Git is properly installed or not.

     git --version
    

macOS

  1. Download Git (masOs version) from git.scm.com

  2. Open the downloaded macOs version and follow the instructions to install it. Unless otherwise told, use the default settings.

    (And if you get stuck and don’t know how to proceed go here to see what to do next)

Open the terminal and type this command to check whether Git is properly installed or not.

git --version

Linux

Open your terminal and type :-

sudo apt-get install git

Step 2: Configure Git

  1. Open your terminal and set up your username and email :-
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
  1. Verify your configuration using the following commands :-
git config --global user.name
git config --global user.email

Step 3: Create a GitHub Account

  1. Go to github.com.

  2. Click "Sign up" and IMPORTANT: In the email field, enter the same email address you used in the Git configuration command: git config --global user.email "" and then complete the sign up process.

Step 4: Add an SSH Key to the GitHub

Why use SSH ?

SSH keys let you securely connect to GitHub without typing your username and password every time.

Steps to Add an SSH Key :-

  1. Generate an SSH Key Open your terminal and type:

     ssh-keygen -t rsa -b 4096 -C "your.email@example.com"
    

    Press Enter to accept the default file location. Set a passphrase if you want (optional).

  2. Copy the SSH Key Run this command to copy the key:

     cat ~/.ssh/id_rsa.pub
    

    Select and copy the entire output.

  3. Add the Key to GitHub

    • Go to GitHub SSH Settings.

    • Click "New SSH key"

    • Paste your key into the "Key" field and give it a title.

    • Click "Add SSH key"

Test the SSH Connection Run this command to test:

ssh -T git@github.com

If successful, you will see a welcome message from GitHub.

Cloning the ChaiCode Repository

Step 1: Clone the Repository

  1. Go to the GitHub Repository which you want to clone then click on code and copy the HTTPS link :-

  2. Open your terminal.

  3. Type this command to download the project :-

     git clone git@github.com:ChaiCode/example-repo.git
    

  4. Go into the project folder :-

     cd example-repo
    
     code .
    

    Basic Git Commands

    Common Commands

     git commit -m "Your message"
    
    • See the status of your changes :-

        git status
      

      After creating one.txt file :-

    • Save changes you made to files :-

        git add <file>
      

    • Record your changes with a message :-

        git commit -m "your message"
      

    • Send your changes to GitHub :-

        git push
      

    • Get the latest updates from GitHub :-

        git pull
      
      • If some changes happened or someone or me added something in the repo on GitHub and you want to see or add the update then use git push, Let’s take an example

          git pull
        

    • See a history of changes :-

        git log
      

See a brief history of changes :-

git reflog

Commit Message Rules

  1. Use present tense (i.e. "Add feature" not "Added feature").

  2. Start with a capital letter.

  3. Keep it short (50 characters or less).

  4. Use tags like these to explain your changes:

    • feat: for new features.

    • fix: for bug fixes.

    • docs: for documentation updates.

Examples:

feat: Add tea selection feature
fix: Fix login issue
docs: Update README with chai varieties

Branching Workflow

What Are Branches?

Branches let you work on a feature without affecting the main project. When you're done, you can add your work to the main branch.

Create and Switch Branches

git checkout feature/tea-menu
  • Create a branch :-

      git branch feature/tea-menu
    

  • Switch to a branch :-

  • Add your branch to the main branch :-

      git checkout main
      git merge feature/tea-menu
    
    • (Below image) i added the tea-List.txt file on feature/tea-menu, then switch to main branch and at last i merged the feature/tea-menu branch into main branch

  • If there are conflicts, fix them in your code editor and save it.

How to Create Pull Requests (PR)

1. Fork the Repository (If you don't own it)

If you're contributing to a project you don't own, you need to create a copy of it in your own GitHub account. This is called "forking."

  • Go to the repository on GitHub.

  • Click the "Fork" button in the top right corner.

  • GitHub will create a copy of the repository in your account.

2. Clone the Repository to Your Local Machine

Now you need to download the forked repository to your computer.

  • Go to your forked repository on GitHub.

  • Click the "Code" button and copy the repository's URL (HTTPS or SSH).

  • Open your terminal and navigate to the directory where you want to store the project.

  • Clone the repository:

      git clone <repository_url>
    
      cd <repository_name>
    

3. Create a New Branch

It's crucial to create a new branch for your changes. This keeps your work separate from the main branch.

  • Create a new branch and go to the new branch:

      git branch <give branch name>
      git checkout <your branch name>
    

4. Make Your Changes

Now make the necessary changes to the code using your code editor.

5. Commit Your Changes

After making your changes, you need to commit them to your local branch.

  • Stage your changes and commit your changes with a descriptive message :-

      git add
      git add <file>
      git commit -m "message"
    

6. Push Your Branch to Your Fork on GitHub

Upload your local branch to your forked repository on GitHub.

git push origin <your_branch_name>

7. Create the Pull Request on GitHub

  • Go to your forked repository on GitHub.

  • You should see a banner that says "Compare & pull request" for your recently pushed branch. Click it.

  • On the pull request page:

    • Base repository: This should be the original repository you forked from.

    • Base branch: This is the branch in the original repository you want to merge your changes into

    • Head repository: This should be your forked repository.

    • Compare branch: This is your branch with the changes.

  • Write a clear and informative title and description for your pull request. Explain what changes you made and why.

  • Click "Create pull request."

    Best Practices

    1. Save your progress often with commits.

    2. Write clear commit messages so others understand your changes.

    3. Always pull the latest updates before starting work to avoid conflicts.

That's all you need to know to get started with Git and GitHub.