Onboarding Guide: Mastering Git and GitHub at ChaiCode

Photo by Richy Great on Unsplash

Onboarding Guide: Mastering Git and GitHub at ChaiCode

Welcome to ChaiCode Cohort! As a developer, you'll often work collaboratively on projects that require seamless version control and efficient code management. This onboarding documentation is designed to help you quickly get started with Git and GitHub, two essential tools for modern software development.

So, first we’ll see what is Version Control System (VCS) and then understand what is Git and GitHub and why they are used.

What is Version Control System?

VCS which is short for Version Control System, is a tool that helps manage and track changes to source code or other files over time. VCS is essential for software development and otherprojects where maintaining a history of changes, collaboration, and versioning is critical.

Need of Version Control System?

  1. Tracking Changes : It records changes to files over time, enabling developers to see who changed what and when.

  2. Collaboration : Multiple people can work on the same project simultaneously without overwriting each other’s work.

  3. Branching and Merging : Developers can create separate branches for different features or experiments and later merge them into the main project.

  4. Version History : It keeps a history of all changes, making it easy to revert to previous versions if needed.

  5. Conflict Resolution : Helps manage and resolve conflicts when multiple developers make changes to the same file.

  6. Backup and Recovery : Acts as a backup for the project.

Now we have a good understanding on VCS so it’s time to get started on Git and GItHub.

What is Git?

Git is a free, open-source, distributed version control system used to track changes in files and coordinate work on projects among multiple people.

Why is Git Used?

Git is used for various purposes such as:

  1. Version Tracking: Git keeps a history of all changes made to a project, allowing you to revisit or restore previous versions at any time.

  2. Collaboration: Git allows multiple developers to work on the same project simultaneously.

  3. Branching and Merging: Git provides a branching system that lets developers create isolated environments for working on new features, bug fixes, or experiments.

  4. Error Recovery: With Git, you can easily undo changes, revert commits, or recover deleted files, making it an invaluable tool for development.

  5. Open Source and Versatile: Git is free, open-source, and works on any operating system.

What is GitHub?

GitHub is a cloud-based platform for hosting Git repositories. It provides collaboration features, a web interface, and tools for managing projects.

Why is GitHub used?

  1. Centralized Code Hosting: GitHub acts as a central repository where developers can store and access their code from anywhere.

  2. Collaboration and Teamwork: GitHub simplifies teamwork by allowing developers to work on the same repository, track progress, and review each other's changes.

  3. Project Management Tools: GitHub includes tools like Issues, Milestones, and Projects to help teams organize tasks, track bugs, and manage workflows efficiently.

  4. Version Control in the Cloud: By integrating Git's version control with a web interface, GitHub makes it easier to manage changes in a collaborative environment.

  5. Open Source Community: GitHub hosts millions of open-source projects, making it a hub for developers to learn, contribute, and collaborate.

Importance of Git and GitHub in team collaboration at ChaiCode Cohort?

At ChaiCode Cohort, effective team collaboration is essential for delivering high-quality software. Git and GitHub play a central role in streamlining this collaboration, ensuring that all team members can work efficiently and cohesively.

Get started with Git:

Installing Git

Windows:

  1. Download Git

  2. Install GIt:

    • Run the downloaded .exe file.

    • Adjust the Path environment: select the option to add git to the system PATH

  3. In cmd , type git --version to check if you have installed git.

macOS:

  1. Open Terminal and type:

     brew install git
    
  2. Verify the installation:

     git --version
    

Linux:

  1. Use your package manager:

     sudo apt-get install git    # For Debian/Ubuntu
     sudo yum install git        # For Fedora/Red Hat
    
  2. Verify the installation:

     git --version
    
  • Configure Git:

  1. After the installation, configure Git with your name and email.
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

  1. Verify the Configuration:
git config --global --list

Get Started with GitHub

  • Creating GitHub Account: To create your account, you need to go to GitHub's website and fill out the registeration form.

  • Sign up to GitHub using email and create a strong password:

  • Once you sign up with your email then you are able to see Your github repository and also save your code in the github through pushing your code.

Let's Git

Creating Remote Repo:

  • Create a new repository on GitHub, Follow this link.

    Give your repository a name, and description(optional), choose if you want to make it a public or a private repo(only you and the people you give access can see a private repo), and you can also add a readme and a license if you want. Otherwise, leave all that options as it is and click create repository.

    Your repo is created. 🥳

Initializing Git in folder:

  1. Open your Project directory in command prompt or in bash

    • You can use VSCode or any other Code Editor

    • Make sure your working directory is correct

    • Use "git init" command to initailize git into your project directory.

    git init

Basic Git Commands.

CommandWhat it does
git initInitialise a new git repo (short form for repository)
git add <file>Staging a particular file for commit
git add .Staging all of the files in the current directory for commit
git commit -m “message”Committing the staged changes with a message
git logChecking the history of commits
git diffComparing the before & after states of working file
git pushPushing commits in a remote repo
git pullPulling / fetching & merging the changes made in a repo
git branchLists down all the branches
git branch <name>Creates a new branch
git checkout <branch>Switch to a specific branch
git merge <branch>Merge a branch to a current branch
git reset <file>Unstage a file (file remains modified)
git reset —hard <file>Unstage a file (modifications are removed as well) (use cautiously)
git stashSaving changes without committing
git stash popReapply stashed changes
git statusShows the condition of the working directory
git clone <url>Clone a repo from a URL
git fetchretrieve latest changes from a remote repo (does not merge them)
git remote add <name> <url>Add a remote repo
git rebase <branch>Reapply commits on top of another branch

Commonly Used Commands

  1. Check repository status:

     git status
    
  2. Stage changes:

     git add <file>
    
  3. Commit changes:

     git commit -m "Your message"
    
  4. Push changes to GitHub:

     git push
    

  5. Pull updates from GitHub:

     git pull
    
  6. View commit history:

     git log
    

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

Branching Strategy

  • Main Branch: Stable production-ready code.

  • Development Branch: Active development.

  • Feature Branches: Specific features or fixes.

Creating and Switching Branches

  1. Create a new branch:

     git branch feature/tea-menu
    
  2. Switch to the branch:

     git checkout feature/tea-menu
    
  3. Merge changes back to the main branch:

     git checkout main
    
  4. git merge feature/tea-menu

     4. Push the branch to GitHub:
     ```bash
     git push origin feature/tea-menu
    

Pull Requests (PR)

Creating a Pull Request

  1. Push your branch to GitHub.

  2. Go to the repository on GitHub and click Pull Requests.

  3. Click New Pull Request.

  4. Add a description and request reviewers.

Best Practices

  • Commit Regularly: Avoid large, infrequent commits.

  • Descriptive Messages: Write meaningful commit messages.

  • Pull Updates: Regularly pull changes to minimize conflicts.

Conclusion

That’s it for today’s introduction to Git and GitHub! These tools might seem a bit overwhelming at first, but with a little practice, they’ll become second nature. Start by installing Git, experimenting with the basic commands, and setting up your first repository on GitHub.

Remember, Git helps you manage your code locally, and GitHub lets you share and collaborate with others. Together, they make development smoother and more organized.

Link to Further Learning Resources
Provide links to resources like: