# Git & GitHub: Onboarding Docs🚀

In this document, you will learn why Git and GitHub are the backbone of our ChaiCode Cohort Company. You might have heard about **pushing** and **pulling** before—gym lovers might relate these terms to their push-pull-leg routine—but in the development world, it’s a completely different story. Before jumping into the tutorial, we want to ensure that our new hires actually understand the purpose behind these tools.

Usually, when we explore any topic, we first analyze the **‘what’** and then proceed to the **‘why.’** But this time, let’s apply some reverse engineering to get a better grasp of things.

### Why ‘Git’?

Most of us have used or at least heard of **Google Docs.** It’s a tool that records changes and keeps a history of previous versions, making it easy to navigate changes or collaborate with a team. Without this tracking system, teamwork would quickly descend into chaos.

*Imagine you pour your heart and soul to write a piece of content only for your teammate to come in , sweep off the content and rewrite it without realizing you've already made changes.* **The frustration.**

> “What just happened??”  
> “Sorry mate , I didn’t know you already made changes!”

Similarly, in the real world of development, multiple people work collaboratively as a team on a single codebase, with each developer focusing on different sections (modularity). To manage this, a tracking system was introduced specifically for coding purposes—this system is called a **Version Control System (VCS)**, and it runs locally on your computer.

While there are several VCS options available, the **winner** in the world of VCS is **Git**.

When you initialize Git in your project using `git init`, it creates a hidden `.git` folder that stores all the version history and metadata of your code. If you share your project by copying it to someone else (e.g., via USB), they will also get this `.git` folder. As long as they have Git installed, they can use commands like `git log` to view the history of changes you've made to the code.

### Why ‘GitHub’?

Sending code through physical storage like USB drives is outdated. Developers today are spread across the globe, working together in real-time. So, we need a **cloud storage solution,** replacing USB drives with services like Google Drive or Mega. While you can share your code and the `.git` folder via these cloud services ;you could still see version history, logs, and commits since they stay inside the .git folder. However, these services are designed for general media like videos and images, not for coding collaboration. That's why **GitHub** exists—designed specifically for version control and seamless collaboration.

### Importance of Git and GitHub

* **Git Advantages:**
    
    * Keep a record of all changes
        
    * See progress over time
        
    * Work on different parts of a project without interfering with others
        
    * Use it anywhere, even without an internet connection
        
    
    **GitHub Advantages:**
    
    * Cloud-based hosting that provides Easy collaboration (pull requests)
        
    * View anyone’s changes in the codebase around the globe
        

### Installation Setup:Windows

1. Download the Standalone Installer for Windows from Git’s official website [https://git-scm.com/downloads](https://git-scm.com/downloads) and follow the prompts to complete the installation by running the .exe.
    
    In cmd , type `git --version` to check if you have installed git.
    
    If you haven’t created a GitHub account , then follow this official documentation of GitHub [https://docs.github.com/en/get-started/start-your-journey/creating-an-account-on-github](https://docs.github.com/en/get-started/start-your-journey/creating-an-account-on-github)
    
    Now Open ‘Git Bash ‘ .
    
    Run the following commands to set your name and email of your GitHub account
    
    ```bash
    git config --global user.name "Your Name" 
    git config --global user.email "your.email@example.com
    ```
    
2. "Once you've set your name and email globally using the git config --global command, Git will use those settings automatically for every project you work on, so you don't need to enter them every time you make a commit
    
3. Run the following command to check if your Git Configuration was set correctly :
    
    ```bash
    git config --global --list
    ```
    
    If you see values like these , then the configuration was set correctly.
    
    ```bash
    user.name=Your Name 
    user.email=your.email@example.com
    ```
    
4. To set up an SSH key so that you don't have to enter your password every time you interact with GitHub, enter this in the Git Bash.
    

```bash
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
```

Press **Enter** to save it in the default location (`~/.ssh/id_rsa`).Enter a \*\*Passphrase(\*\*optional) else leave it empty and proceed.

5. Type the following commands in the Bash
    
    ```bash
    eval "$(ssh-agent -s)"
    ```
    
    The output will show something like: `Agent pid 1234`.
    
    ```bash
    ssh-add ~/.ssh/id_rsa
    ```
    
    ```bash
    clip < ~/.ssh/id_rsa.pub
    ```
    
    This command would copy the SSH public key to your clipboard.
    
6. Now go to [https://github.com/settings/keys](https://github.com/settings/keys)
    
7. In the "Title" field, name your key (e.g., "My Laptop").
    
8. Paste the copied key into the "Key" field.
    
9. Click **Add SSH key**.
    
10. Test if the SSH key is working by running:
    
    ```bash
    ssh -T git@github.com
    ```
    
    If successful you will see,
    
    `Hi your_username! You've successfully authenticated, but GitHub does not provide shell access.`
    

SSH allows you to securely authenticate with GitHub without entering your password each time by using an SSH key pair. Once you add your public key to GitHub, you can use the SSH URL ([git@github.com](mailto:git@github.com):username/repo.git) to push and pull without authentication prompts.

### Cloning

Cloning in Git refers to the process of copying a remote repository (often public) including its histories to your local machine. This allows you to work on the project locally, make changes, and commit those changes independently from the remote repository. However, the changes you make locally won't affect the remote repository unless you push your changes back to the remote.

**Note**:If you clone a public repository you don't own , you can't push changes unless you have permission. You'll get a 403 error.

**Fork** the public repository to create a copy in your account.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736675763124/e5a6ac9f-0081-40e2-ab67-9616ab6ffe86.png align="center")

Then press ” Create fork” .Click on “Copy URL To clipboard”

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736675891693/35258b28-5637-41c6-a90d-b7029930893a.png align="center")

2. Now open your Command Prompt , and then type the following command
    
    ```bash
    git clone <the-url-which-you-copied>
    ```
    
    Enter `cd <cloned-project-folder-name>` to go the folder directory. Now enter `code .` to go to the folder with your vs code
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736666058801/49233fc7-3612-47a2-b892-ee8f83f04dd7.png align="center")
    
3. Now open your Vscode terminal (Ctrl+Shift+\`) to execute further git commands.
    

### Basic Git commands

1. `git init` - Adds a .git folder to the current folder which you are working on
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736666234085/a5b412a5-481d-45a2-a72c-46d5e3eb1ed1.png align="center")

2. `git add .` - to add the entire file contents
    
    `git add <foldername>`\-to add the particular folder
    
    `git rm —cached <foldername>` - to untrack / remove the tracked file
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736666696239/067e0412-d4ce-422b-b3cf-7f9719077261.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736667379948/8a96ac08-d937-4cc2-9f3d-c788df597165.png align="center")
    
    Now before moving on , there are 3 important terms to understand with the files/folders which have been initialized with .git folder
    

| State name | Description |
| --- | --- |
| Untracked | The files have not been added yet |
| Unstaged | The files have been added , but they have been modified and haven’t been added after the modification |
| Staged | The files have been added and the changes have been marked |

3 .`git status` -shows the current state of tracked and untracked files, indicating whether they are modified, staged, or untracked.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736667653271/038edaff-a88d-40db-a7b5-fc9c66f7b9d6.png align="center")

4 . `git commit -m "message"` - save the staged changes to the repository with a message about what action has been taken

Note: A commit can only be made if the file has been **modified**, meaning it is different from the previous commit.

One line was removed from `one.txt`, making it **unstaged**. The line was then added back, and the file was **staged** again. After staging the changes, the file was **committed**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736669100815/119237b6-2668-4d86-ab4a-4328daa82c36.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736668583287/1d66d811-86a0-4781-ad78-a57b1d900cfc.png align="center")

***Note: m - unstaged; a -staged ;u - untracked***

### Rules to be followed while writing a message

1. Use the present tense ("Add feature" not "Added feature").
    
2. Capitalize the first letter.
    
3. Keep the message short (50 characters or less).
    
4. Use prefixes like `fix:`, `feat:`, `chore:`, `docs:` for categorization.
    
    1. fix - bugs / issues related
        
    2. feat - addition/removal of a feature/functionality
        
    3. chore- routine maintenance /updates related
        
    4. docs - changes in the documentation
        

5 . `git log` - Shows history of all the previous commits

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736668676160/071f3a9a-d54e-44f2-941c-7728719c5bc9.png align="center")

6. `git push`\-upload all your local commits to a remote repository
    

```bash
git push origin <your-branch>
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736672049934/381194be-0d85-4aff-851c-b843d00cd3c7.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1736672089031/90bc3c65-42e1-4845-bb14-b4f558597981.png align="center")

Some Shorthands:

* `git commit -am "message"`: Stages and commits all modified tracked files with a single commit message.(Only if it is tracked)
    
* `git log --oneline`: Displays the commit history with each commit shown in a single line, showing the abbreviated commit hash and message.
    

### In the part 2 of Git and Github we would learn about branching workflows , merge and pull requests . Thankyou!!
