Lesson 8 of 60 – Git Bash & Terminal Basics
13%

Git Bash & Terminal Basics

Git Bash is a terminal environment commonly used on Windows to run Git commands and other command-line tools. Learning basic terminal commands makes it easier to navigate folders, create files and directories, and work with Git repositories.

Note: Git Bash is especially useful for Windows users, but Git commands can also be run from other supported terminal applications.

1. What is Git Bash?

Git Bash is a command-line environment included with Git for Windows. It provides a terminal where you can run Git commands and common Unix-style shell commands.

git --version

2. What is a Terminal?

A terminal is a text-based interface used to interact with a computer by typing commands.

Instead of clicking buttons and folders, you can type commands to perform tasks.

pwd
ls
cd

3. Opening Git Bash

After installing Git for Windows, you can open Git Bash from the Windows Start menu.

You can then enter Git commands directly in the terminal.

git --version

4. Git Bash Prompt

When Git Bash is open, you will see a command prompt where you can type commands.

The prompt may display information about your user and current directory.

$

Type a command and press Enter to execute it.

5. Checking the Current Directory

The pwd command displays the current working directory.

pwd

Knowing your current directory is useful before running file and Git commands.

6. Listing Files and Folders

The ls command lists files and directories in the current location.

ls

It is useful for checking what is available in the current directory.

7. Detailed File Listing

Git Bash supports options that provide additional information about files and directories.

ls -l

This can display information such as permissions, ownership, file size and modification information.

8. Changing Directory

The cd command is used to change the current directory.

cd project

This moves into the project directory if it exists.

9. Moving to the Parent Directory

Two dots .. represent the parent directory in common command-line environments.

cd ..

This moves one level up from the current directory.

10. Returning to the Home Directory

The tilde character ~ commonly represents the user's home directory in Unix-style shells.

cd ~

This can be used to move back to the home directory.

11. Creating a Directory

The mkdir command creates a new directory.

mkdir git-practice

This creates a directory named git-practice.

12. Entering a New Directory

After creating a directory, you can enter it using the cd command.

mkdir git-practice
cd git-practice

13. Creating a File

Git Bash supports commands for creating files. One commonly used command is touch.

touch index.html

This creates an empty file if the file does not already exist.

14. Viewing a File

The cat command can display the contents of a text file.

cat index.html

It is useful for quickly viewing text files from the terminal.

15. Clearing the Terminal

The clear command clears the visible terminal screen.

clear

Clearing the screen does not delete your project files or Git history.

16. Git Version Command

The git --version command displays the installed Git version.

git --version

This is useful for confirming that Git is available in the terminal.

17. Git Help

Git provides built-in help for commands.

git help

You can also request help for a specific command:

git help status

18. Git Status

The git status command displays information about the current Git repository.

git status

It can show the current branch and changes in the working tree and staging area.

19. Initializing a Repository

The git init command initializes a new Git repository in the current directory.

git init

Git creates repository metadata inside a hidden .git directory.

20. Git Status After Initialization

After initializing a repository, run:

git status

Git will show information about the newly initialized repository and its current branch.

21. Creating a Practice Project

You can create a practice project using:

mkdir my-project
cd my-project
git init

This creates a directory and initializes it as a Git repository.

22. Checking Files in a Git Repository

Create a file and check the repository:

touch index.html
git status

Git will identify the new file as an untracked file.

23. Staging a File

Use git add to place a file into the staging area.

git add index.html

Then check the repository:

git status

24. Creating a Commit

After staging a file, create a commit:

git commit -m "Add homepage"

The commit records the staged changes in the repository history.

25. Viewing Commit History

After creating commits, you can view the history using:

git log

This displays information about previous commits.

26. Git Bash Navigation Example

mkdir git-demo
cd git-demo

pwd
ls

touch index.html

git init
git status

This example demonstrates basic directory navigation and Git commands.

27. Git Bash and Git Commands

Git Bash provides the terminal environment, while Git provides the version control commands.

Command Purpose
pwd Show current directory
ls List files and folders
cd Change directory
mkdir Create directory
git status Show Git repository status
git init Initialize Git repository

28. Common Git Bash Mistakes

  • Running Git commands outside the intended repository
  • Using the wrong directory
  • Forgetting to check the current location
  • Typing commands incorrectly
  • Deleting files without checking the command
  • Confusing Git commands with ordinary shell commands

Use pwd and git status frequently while learning.

29. Basic Git Bash Practice

mkdir git-practice
cd git-practice

touch index.html

git init
git status

git add index.html
git commit -m "Initial commit"

git log

This practice sequence introduces directory navigation, repository creation, staging, committing and viewing history.

30. Summary of Git Bash

Git Bash provides a convenient command-line environment for Git users on Windows. By learning basic terminal commands such as pwd, ls, cd and mkdir, you can navigate your project efficiently.

You can then use Git commands such as git init, git status, git add and git commit to manage your project.

In the next lesson, we will learn how to create a Git repository.

📌 Key Points

  • Git Bash is a terminal environment included with Git for Windows.
  • A terminal allows you to run commands using text input.
  • pwd shows the current directory.
  • ls lists files and directories.
  • cd changes the current directory.
  • mkdir creates a directory.
  • touch can create an empty file in Git Bash.
  • git --version displays the installed Git version.
  • git init initializes a repository.
  • git status displays the current repository state.
  • git add stages changes.
  • git commit records staged changes.

🧠 Quick Quiz

Question: Which command is used to display the current directory in Git Bash?