πŸš€ Git and GitHub Fundamentals for Beginners

#Day7ofDevOpsBlog

Β·

4 min read

πŸš€ Git and GitHub Fundamentals for Beginners

Hello, Tech Enthusiasts! 😎 Lets Dive into GIT and GITHUB today...

What is Git? πŸ€”

Git is a powerful version control system (VCS) that helps you manage changes to your code over time (maintains versions for each change you make in your file). Imagine you're writing a novel. Each draft you save is a snapshot of your work at that moment. Git does the same for your code, allowing you to track changes, revert to previous versions, and collaborate with others to avoid any code confusions between different developers sitting all across the world.

What is Version Control? πŸ“š

Version control is a system that records changes to a file or set of files over time so you can recall specific versions later in case of any problems. With version control, you can:

  • Track changes πŸ•΅οΈβ€β™‚οΈ (like who made the changes, when were they made, what was the change etc.)

  • Revert files back to a previous state βͺ (in case of any issues with the recent state of our file)

  • Compare changes over time πŸ†š (to solve the issues)

  • Collaborate with others without overwriting each other's work 🀝

Version Control System vs. File System πŸ“‚

A file system is where you store files on your computer. A version control system (VCS) like Git adds a layer of tracking and managing changes to these files. Here’s how they differ:

  • File System: Just stores files and no tracking is there thus if a file gets delete, there is no record and thus can never be recovered.

  • Version Control System: Tracks changes, maintains history, and supports collaboration. Thus, ensuring that it can be recovered if lost.

What is Git Bash? πŸ–₯️

Git Bash is composed of two words namely GIT which has commands to perform specific git tasks and BASH which gives us interface to run these commands. So, it is a command-line interface that allows you to interact with Git. It's like the terminal on macOS/Linux or the Command Prompt on Windows, but with Git commands built-in. It helps you run Git commands to manage your repositories.

Git Workflow Basics 🚦

Untracked, Staged, and Tracked Files πŸ“„

  • Untracked Files: New files that Git doesn't know about yet.

  • Staged Files: Files marked to be included in the next commit.

  • Tracked Files: Files that Git is already keeping track of.

Essential Git Commands πŸ› οΈ

  1. Initialize a Git Repository 🏁

     git init
    

    Creates a new Git repository .git (used to store the git revision history) in your current directory.

  2. Add Files to Staging Area βž•

     git add <filename>
    

    Adds a file to the staging area.

  3. Commit Changes πŸ“Œ

     git commit -m "Your commit message"
    

    Records the changes in the repository with a message. Here, message is important so that with each change who ever sees knows why or for what was that change done thus the message should be relevant as well.

  4. Check the Status of Files πŸ”

     git status
    

    Shows the status of changes as number of files in a directory which are untracked, modified, or staged.

  5. View Commit History πŸ“œ

     git log
    

    Displays the commit history.

  6. Simplified Commit History πŸ“‹

     git log --oneline
    

    Shows a condensed version of the commit history.

  7. Restore Files πŸ› οΈ

     git restore --staged <filename>
    

    Moves a file from staging area to untracked area.

Branching in Git 🌳

Branching allows you to create separate lines of development. It’s like having different drafts of your novel, each exploring a different plotline.

Branching Commands 🌿

  1. Create a New Branch 🌱

     git branch <branch-name>   OR  git checkout -b <branchname>
    

    Creates a new branch.

  2. Switch Branches πŸ”„

     git checkout <branch-name>
    

    Switches to the specified branch.

  3. List Branches πŸ“œ

     git branch
    

    Lists all branches in your repository.

  4. Switch to a Branch 🌐

     git switch <branch-name>
    

    Another way to switch branches.

What is GitHub? πŸ™

GitHub is a cloud-based platform (GUI) that hosts Git repositories and provides tools for collaboration, code review, and project management, making it easier to work and collaborate with others.

Basic GitHub Commands 🌐

  1. Clone a Repository πŸ“‚

     git clone <repository-url>
    

    Copies a repository from GitHub to your local machine.

  2. Push Changes πŸ“€

     git push
    

    Sends your committed changes to GitHub.

  3. Pull Changes πŸ“₯

     git pull
    

    Fetches and integrates changes from GitHub to your local repository.

Difference Between Git and GitHub πŸ”„

  • Git: A distributed version control system to manage code history. It is a command line interface (CLI).

  • GitHub: A hosting service for Git repositories with added features for collaboration and project management between teams. It is a graphic user interface (GUI).

Conclusion 🎁

Having knowledge of Git and GitHub is very important for any technical person as in today's time most of the company's use these to improve their virtual workspace and increase collaboration among their teams. Happy learning! πŸš€

Β