Skip to main content

Command Palette

Search for a command to run...

Git & GitHub: Onboarding Docs🚀

Updated
•7 min read•View as Markdown
Git & GitHub: Onboarding Docs🚀
K

I am a B.Tech Computer Science student in my second year, aspiring to become a software engineer with a strong interest in web development. Currently, I am exploring development while actively practicing Data Structures and Algorithms (DSA) to enhance my problem-solving skills and speed. I am passionate about contributing to open-source projects and aim to work for a product-based startup or an MNC in the future.

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 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

    Now Open ‘Git Bash ‘ .

    Run the following commands to set your name and email of your GitHub account

     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 :

     git config --global --list
    

    If you see values like these , then the configuration was set correctly.

     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.

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.

  1. Type the following commands in the Bash

     eval "$(ssh-agent -s)"
    

    The output will show something like: Agent pid 1234.

     ssh-add ~/.ssh/id_rsa
    
     clip < ~/.ssh/id_rsa.pub
    

    This command would copy the SSH public key to your clipboard.

  2. Now go to https://github.com/settings/keys

  3. In the "Title" field, name your key (e.g., "My Laptop").

  4. Paste the copied key into the "Key" field.

  5. Click Add SSH key.

  6. Test if the SSH key is working by running:

    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: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.

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

  1. Now open your Command Prompt , and then type the following command

     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

  2. 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

  1. 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

    Now before moving on , there are 3 important terms to understand with the files/folders which have been initialized with .git folder

State nameDescription
UntrackedThe files have not been added yet
UnstagedThe files have been added , but they have been modified and haven’t been added after the modification
StagedThe 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.

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.

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

  1. git push-upload all your local commits to a remote repository
git push origin <your-branch>

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!!