Guide to Git Bash for windows

Guide to Git Bash for windows

The easiest guide to Git Bash for windows download and, the basic configurations needed to install Git bash commands to manage your repositories

What is Git bash

  • Git bash (for Windows, Linux, or Mac) is a source control management system that you can download and install on your computer where you can type some Git commands to make source code management easier through versioning and the commit history.

Difference between the terms Git and Git Bash

  • Git - a distributed version control system that makes tracking changes very easy, where you can compare different versions of the same source code file.

  • Git bash - is not a GUI software. Instead, it's a command line prompt that you will only use to write and run commands.

Download Git Bash for Windows

To start downloading, follow these steps:

Testing Git bash Windows installation

  • The git bash terminal opens up, where you will write your Git commands.

  • Type in the following command: git version

  • Git should respond by providing the Git version

Git bash Windows configurations

  • Now Git has been installed and responds correctly to commands.

  • It's required to provide Git with two basic configurations to be able to manage repositories

  • Make sure your Git bash command prompt is open

  •     //Apply the following command to configure your name:
        git config --global user.name "Your Name"
        //Then apply the next command to configure your email:
        git config --global user.email "your@email.com"
        //To make sure that both configurations have been set correctly we can check by typing the following command:
        it config --global --list
    

Git configurations explained

  • git config is primarily used to set or get any Git configurations.

  • After git config, both --global or --system can be used as a parameter to let Git easily find the configuration file to edit and modify the supplied configurations

  • --system tells Git to look for the configuration file placed system-wide /etc/gitconfig which applies to every user on the system

  • --global tells Git to look for the configuration file set at the user level ~/.gitconfig which is specific to each user. That's why it made sense to configure the username and email with the --global for a particular user and not with --system for all users.

  • user.name and user.email will set the username and email.

  • It's not necessary to get or set Git configurations through commands; you can manage the settings by editing the configuration files directly.

  • Git, by default, displays most of its output on Git bash in a colored format. However, if you do not prefer this feature you can turn it off by applying the following command: git config --global color.ui false

Some useful Windows Git bash commands

  • pwd: This command will respond with the current directory location, the command pwd responded with the root location.

  • ls : This command will respond by listing all the files and directories at the current location

  • It appears that the default location of the ls command is the same as the path where git-bash.exe is. Which is not desired as a best practice to create projects and files at this location.

  • So, to change the default location, Go to your file explorer and open the C drive and create a new folder called "Git_Projects" while your Git bash terminal is open, write the following command: cd "C:\Git_Projects"

  • Make sure you include the double quotes otherwise, Git will not be able to find your location, Now if you rerun the ls command you will get different results

  • An alternative to running the cd command is, while your Git terminal is closed, on your Windows file explorer, go to the created "Git_Projects" folder then right-click anywhere.

    You should find two Git options in the Windows file explorer context menu which are "Git GUI Here" and "Git Bash Here".

  • Click "Git Bash Here", and that should open Git bash with your location set to the "Git_Projects" folder precisely the same as running the cd command

For more details about the different git configurations you can ask Git itself for help through the following command: git help config

Some more useful commands

  •     ls → lists everything that's in my current directory
        pwd → current directory location
        cd → go into that folder
        cd .. → brings me back to one directory up
        clear → to clear up my terminal
        cd /  →root director**
        cd ~  →user directory
        cd <folder/folder/folder> ** <> means to add your own folder names that exist on your computer.
        mkdir <folder> → make folder
        open <folder> **for windows use: start <folder>
        touch index.html  **for windows use: echo "" > index.html
        open index.html **for windows use: start index.html
        open . **for windows use: start .
        mv index.html about.html
        *Try using the Up and Down arrow.
        rm <file>  →remove file
        rm -r <folder>  →remove folder
        say hello **(only on Mac)**
    

Git on Visual Studio Code

  • If you are using Visual Studio Code to develop React, Angular, or any type of application, you can use the Git visual integration

  • Once you click Git's source control icon on the left, you can either choose "Open Folder" to open an existing project that's already mapped to a Git remote repository or "Clone Repository" to clone a new remote repository on your local machine.