Git

This exercise guides you through the steps needed to take to properly install and minimally use the git software and the Git Bash terminal on your system.
By the end of this exercise, you will be able to initialize an empty git project anywhere in your computer, or initialize a project on GitHub and clone it to your system.
Guidelines. Use the following references for operations in a (Git) Bash terminal.
- Linux Bash command reference

  1. Only Windows users. Before installing the Git software, I highly recommend you to download and install the most recent version of Nodepad++ text editor on your system, if you do not have it already.
  2. Git installation. Visit the Git downloads website and download the most recent version of the git software to install on your system.
    • Only Windows users. During the installation, the git software may ask you to link your Notepad++ software with git. If given this option, choose it.
    • Only macOS users. One of the easiest ways to install the Git software is via the Homebrew package manager.
      1. First, open a command line terminal and type brew and press Enter key.
        If the terminal returns an error not recognizing Homebrew brew command, it means you do not have brew installed on your system.
        If you do have brew already installed, skip the next step.
      2. In you terminal, copy and paste the following command and press Enter:
        /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
        

        The Homebrew installation may take a while depending on the quality of your network connection.
        Carefully read any questions and message prompted by Homebrew and respond correctly.

      3. Once done, type the following command to install git on your system:
        brew install git
        
  3. Interacting with Git.
    • Depending on your operating system,
      • On Windows systems,
        1. press the Windows key + E to open a Windows explorer.
          explorer-key-shortcut.jpg
        2. Then, navigate to the directory C:\Users\account, where you have to replace account with your Windows account name.
        3. Now right-click on an empty region of the Windows explorer, you should see a menu like the following.
          git.bash.here.png
          Click on “Git Bash Here” to open a Git Bash session. You should see a Bash session opened like the following screen shot,
          git.bash.png
          What is Git Bash? Git Bash is simply a Bash terminal that is tailored for Git usage on Windows.
          The Linux and macOS operating systems have Bash-compatible terminals (shells) that allow interaction with the operating system.
          The Git software was originally built as a Linux application that natively used the Linux terminals for interaction.
          However, Windows system is not fully compatible with Linux terminals and does not have native Linux-compatible terminals.
          Therefore, the Git developers decided to ship the Git software with a dedicated Bash terminal for use on Windows systems, so that Windows users also get the same feeling as Linux and macOS users when dealing with Git software.
      • On Linux / macOS systems.
        1. Simply search for terminal in the search box of your operating system and open a terminal.
        2. Then type cd ~ and press enter. This will take you to home directory of your system.
        3. Then type open . in your terminal and press enter to open a macOS finder in the same location as your home folder.
    • Now, within your terminal (whether Git Bash or Linux/macOS terminal), type pwd and press enter.
      Why? This Bash command displays the current working directory where you are.
      It should print the path to the home directory of your system, because you are already in the home directory.
    • Now type ls -a and press enter.
      Why? This Bash command will display a list of all files and folders in the home directory of your computer.
      The -a flag requests the Bash terminal to show all files (including hidden files).
      Note that any file or folder whose name begins with a . is automatically hidden from your view.
  4. Creating your first Git project.
    There are two ways to create git projects,
    1. Creating a git project on your local system.
      • Now type mkdir git and press enter.
        Why? This Bash command will create a new folder named git within the current directory of your Bash session (which is already your home directory).
        Although you can use any place in your computer to store your Git projects, it is good practice and much easier to keep them all in one place (the git folder you just created).

        Some of you may have already created a git folder in your home directory.
        In such a case, the command mkdir git will lead to an error because the folder already exists.
        Do not panic, ignore the error message and move on to the next step below.

      • Now type ls -l again and press enter.
        Why? If you have successfully created the new folder git in your current directory, this command will show you the new folder in the listing it displays.
        If you cannot find it, you need to reach out to me to identify the roots of the problem.
      • Now type cd git and press enter.
        Why? The cd Bash command stands for Change Directory. Therefore, cd git will change your current working directory from your home directory to the subdirectory git.
      • Now, we want to create a new git project in this folder. Let’s say the name of the project is test.
      • First, we will have to create a test folder where we will store all files and materials related to the test git project. Type the following in the terminal and press enter.
        mkdir test && cd test
        

        This command will create a test subfolder in your git folder and then will change the current directory to wihtin the test subfolder.
        The && simply means and: Make directory test and change directory to test.

      • This is where we want to host our git test project. To initialize an empty Git project here, type the following git command in the terminal,
        git init
        
      • Done. You have successfully created an empty test Git project on your computer.
      • Each and every Git project is always associated with a .git subfolder in the same location where your store your project on your system.
        To ensure you have successfully initiated a Git project, type ls -a in your terminal and press enter.
        This should display a list among which there is .git.
        If you do not see this hidden folder in the list displayed, your test folder is not a git project yet!
      • Of course, your Git project is still empty. But you can now put anything you like in it and make it part of your project.
        For example, we can add an empty text file to it by typing,
        touch README.md
        

        in the Bash terminal and pressing enter.

    2. Creating a git project on a server and cloning the project on your local system.
      This is the easier way of initializing projects and sharing them with other Team members in the project.
      In the follow-up exercises, we will learn how to initialize Git projects using GitHub as the git server.

Comments