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.
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
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
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
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.
The pwd command displays the current working directory.
pwd
Knowing your current directory is useful before running file and Git commands.
The ls command lists files and directories in the current location.
ls
It is useful for checking what is available in the current directory.
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.
The cd command is used to change the current directory.
cd project
This moves into the project directory if it exists.
Two dots .. represent the parent directory in common command-line environments.
cd ..
This moves one level up from the current 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.
The mkdir command creates a new directory.
mkdir git-practice
This creates a directory named git-practice.
After creating a directory, you can enter it using the cd command.
mkdir git-practice
cd git-practice
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.
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.
The clear command clears the visible terminal screen.
clear
Clearing the screen does not delete your project files or Git history.
The git --version command displays the installed Git version.
git --version
This is useful for confirming that Git is available in the terminal.
Git provides built-in help for commands.
git help
You can also request help for a specific command:
git help 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.
The git init command initializes a new Git repository in the current directory.
git init
Git creates repository metadata inside a hidden .git directory.
After initializing a repository, run:
git status
Git will show information about the newly initialized repository and its current branch.
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.
Create a file and check the repository:
touch index.html
git status
Git will identify the new file as an untracked file.
Use git add to place a file into the staging area.
git add index.html
Then check the repository:
git status
After staging a file, create a commit:
git commit -m "Add homepage"
The commit records the staged changes in the repository history.
After creating commits, you can view the history using:
git log
This displays information about previous commits.
mkdir git-demo
cd git-demo
pwd
ls
touch index.html
git init
git status
This example demonstrates basic directory navigation 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 |
Use pwd and git status frequently while learning.
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.
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.
Question: Which command is used to display the current directory in Git Bash?