What's Git and GitHub ?

¡

6 min read

What's Git and GitHub ?

Hi Folks 🔆

Today, we’re going to talk about Git and GitHub. If you’re new to tech, you might have come across these terms and wondered what they mean or why they’re important.

Don’t worry—this blog will help you understand the basics in a straightforward way. Whether you’re working on your own or collaborating with others, Git and GitHub are tools that make managing and sharing your code much easier. Let’s start by breaking down what they are and how they work together.

What Are Git and GitHub?

Git: A Tool to Manage Your Code

Git is a version control system that helps you keep track of changes to your files. Think of it like a smart assistant for your projects—it records what you’ve done, lets you try out new ideas without losing old ones, and helps you undo changes if something doesn’t work.

The great thing about Git is that it works right on your computer, so you don’t need the internet to use it.

GitHub: A Place to Share and Collaborate

GitHub, on the other hand, is an online platform where you can store your Git repositories. It’s like a library for your code, but it also lets you collaborate with others. If Git helps you manage your work locally, GitHub makes it easy to share that work with a team, get feedback, and work together.


Why Use Version Control?

Version control is all about managing your code in a way that’s organized and reliable. Imagine it as having “save points” in a game—you can go back to a previous version anytime without losing your progress.

Without tools like Git, keeping track of changes manually can get messy, especially when working in teams. Git solves this problem by making sure your code is always safe, structured, and easy to manage.


Setting Up Git and GitHub

Step 1: Install Git

To get started, you’ll need to install Git on your computer. Here’s how:

Windows:

  • Download Git from git-scm.com.

    • Follow the installer instructions.

    • Open a terminal and type git --version to verify the installation.

      Copy

           git --version
      

macOS:

    • Open Terminal and type:

      Copy

      bash brew install git

      * Verify with:

      Copy

      bash git --version

Linux:

    • Use your package manager:

      Copy

      bash sudo apt update sudo apt install git

      * Verify with:

      Copy

      bash git --version

Step 2: Configure Git

Once Git is installed, set your username and email:

Copy

git config --global user.name "Your Name"  
git config --global user.email "your.email@example.com"

Step 3: Create a GitHub Account

If you don’t have an account yet, head over to github.com and sign up.


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

What Are Repositories ?

A repository (or repo, for short) is like a folder that holds your entire project, including all its files and their history. It’s where Git tracks everything, from the initial version of your code to the latest changes you’ve made.

Repositories can be:

  • Local: Stored on your computer for personal work.

  • Remote: Hosted on platforms like GitHub, where you can share and collaborate.

Think of a repository as the foundation of your project—it’s the starting point for using Git and GitHub.

What Is a Branch ?

A branch is like a parallel version of your project. It allows you to work on new features or fixes without affecting the main codebase.

The default branch in most repositories is called main (or master in older projects). You can create additional branches to experiment, and once your changes are ready, you can merge them back into the main branch.

Local and Remote Branches in Git

In Git, branches help you organize your work by separating different lines of development. Local branches exist on your computer and allow you to experiment, make changes, and commit locally. Once you're ready, you can push your changes to a remote branch on platforms like GitHub, where your team can collaborate, review, and pull your changes.

  • Local Branches: Used for personal development on your local machine. You can create, switch, and commit changes to these branches without affecting the main codebase.

  • Remote Branches: Copies of your local branches that exist on a remote Git repository. These allow you to collaborate with others and keep your work in sync with the team.

By using both local and remote branches, Git ensures seamless collaboration and helps manage changes efficiently.

Best Practices for Working with Git and GitHub.

  • Commit regularly: Don’t wait too long before saving your work. Small, frequent commits make it easier to track changes.

  • Write clear commit messages: A good message explains what you’ve done. For example:

    • fix: Resolve login issue

    • feat: Add user profile page

  • Pull updates frequently: Always sync your local code with the latest version on GitHub to avoid 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:

Happy coding! 😊 #chaicode

Â