DEV Community

Cover image for Getting Started with Git Bash: A Step-by-Step Guide.
Fynface Carey
Fynface Carey

Posted on

Getting Started with Git Bash: A Step-by-Step Guide.

INTRODUCTION TO GIT BASH
Git Bash is a powerful command-line interface that brings the flexibilty and functionality of Unix-like terminals to Windows. It's very easy to run coommands on the terminal like on the Linux and macOS. Whether you are a new developer or a seasoned developer,Git bash is an essential tool for managing version control, automating tasks, and streamlining your workflow.

Understanding Linux commands is crucial for web developers because many web servers run on Linux, and using command line is often the fastest and most precise way to manage and interact with these systems.

Git bash is built because of windows users, to have commands that works on the Linux and macOS work on windows as well.

Terminal Differences: Linux, macOS, and Windows

Linux and macOS:

● Both Linux and macOS are Unix-based operating systems, which means their terminals
(the command line interface) are very similar.
● In both systems, you can access the terminal by simply searching for "Terminal" in your
applications.
● The command syntax and utilities available in the terminal are quite consistent between
Linux and macOS, making it easier to transfer skills between these systems.

Windows:

● Windows originally used Command Prompt (cmd.exe) and later introduced PowerShell,
a more advanced shell with scripting capabilities.
● Unlike Linux and macOS, Windows is not Unix-based, which means its native
command-line tools and syntax are different.
● However, for consistency with Unix-based systems (like the servers you'll work with), it's
recommended to use Git Bash on Windows.

Why use Git Bash on windows?

Git Bash provides a terminal environment that emulates a Unix shell,providing similar experience to Linux and macOS terminals. These are several reasons:

  1. Consistency Across Platforms:You can use same syntax and commands that you use for both Linux and macOS.
  2. Access to Git and Linux Commands:Git bash comes with commands like ls, cd, pwdand grep, which are not available o command prompt.
  3. Easier for Web Development:When setting up your development environment, Git bash helps ensure compatibility and reduces friction.

Essential Commands
Let's dive in on the commands you'll need to know with examples.

  1. pwd (Print Working Directory)
    Definition: Displays the full path of the current directory you are in.
    Example:
    pwd

  2. ls (List Directory Contents)
    Definition: Lists all files and directories in the current directory.
    Examples:
    ls
    ls -l
    ls -a

  3. cd (Change Directory)
    Definition: Changes your current directory to another directory.
    Examples:
    cd /path/to/directory
    cd ..
    cd ~

  4. mkdir (Make Directory)
    ● Definition: Creates a new directory.
    Example:
    mkdir new_directory

  5. rmdir (Remove Directory)
    ● Definition: Removes an empty directory.
    Example:
    rmdir empty_directory

  6. touch
    ● Definition: Creates an empty file or updates the timestamp of an existing file.
    Example:
    touch filename.txt

  7. cp (Copy Files/Directories)
    ● Definition: Copies files or directories from one location to another.
    Examples:
    cp source_file destination_file
    cp -r source_directory destination_directory

  8. mv (Move/Rename Files)
    ● Definition: Moves or renames files or directories.
    Examples:
    mv old_name new_name
    mv file_name /new/location/

  9. rm (Remove Files/Directories)
    ● Definition: Deletes files or directories.
    Examples:
    rm filename
    rm -r directory_name

  10. cat (Concatenate and Display Files)
    ● Definition: Displays the contents of a file.
    Example:
    cat filename.txt

  11. nano or vi (Text Editors)
    ● Definition: Opens a file in a text editor directly in the terminal.
    Examples:
    nano filename.txt
    vi filename.txt

  12. chmod (Change File Permissions)
    ● Definition: Changes the permissions of a file or directory.
    Example:
    chmod 755 filename.sh

  13. chown (Change File Owner and Group)
    ● Definition: Changes the ownership of a file or directory.
    Example:
    chown user:group filename.txt

  14. find
    ● Definition: Searches for files and directories based on specified criteria.
    Example:
    find /path -name filename.txt

  15. grep (Search Inside Files)
    ● Definition: Searches for a specific string or pattern within files.
    Example:
    grep "search_term" filename.txt

  16. df (Disk Free)
    ● Definition: Displays disk space usage for file systems.
    Example:
    df -h

  17. du (Disk Usage)
    ● Definition: Summarizes disk usage of a directory and its contents.
    Example:
    du -sh /path/to/directory

  18. ps (Process Status)
    ● Definition: Displays currently running processes.
    Example:
    ps aux

  19. kill (Terminate a Process)
    ● Definition: Terminates a process using its process ID (PID).
    Example:
    kill 1234

  20. tar (Tape Archive)
    ● Definition: Archives multiple files into a single file or extracts them.
    Examples:
    tar -cvf archive.tar /path/to/directory
    tar -xvf archive.tar

CONCLUSION
Learning Linux commands is a fundamental skill for web developers, as it empowers you to manage your development evironment and servers with precision and ease. The essential commands outlined here serve as the foundation for navigating and managing files, directories and processes in any unix-like system, including Linux, macOS and windows via Git Bash.

Top comments (0)