How to Use Git and Git Bash Locally: A Comprehensive Guide
Table of contentsIntroductionInstallationWindowsmacOSLinuxVerifying InstallationGit Bash BasicsNavigation CommandsFile OperationsKeyboard ShortcutsGit ConfigurationAdditional ConfigurationsBasic Git WorkflowInitializing a RepositoryChecking StatusStaging FilesCommitting ChangesBranching and...

How to Use Git and Git Bash Locally: A Comprehensive Guide
By Nikhil
March 31, 2025
Table of contents Introduction
Installation
Windows
macOS
Linux
Verifying Installation
Git Bash Basics
Navigation Commands
File Operations
Keyboard Shortcuts
Git Configuration
Additional Configurations
Basic Git Workflow
Initializing a Repository
Checking Status
Staging Files
Committing Changes
Branching and Merging
Working with Branches
Merging Branches
Handling Merge Conflicts
Deleting Branches
Remote Repositories
Adding a Remote Repository
Advanced Git Commands
Stashing Changes
Reverting Changes
Interactive Rebase
Troubleshooting
Common Issues and Solutions
Git Best Practices
.gitignore Example
Conclusion
Introduction
Git is a distributed version control system that helps you track changes in your code, collaborate with others, and maintain a history of your project. Git Bash is a terminal application for Windows that provides a Unix-like command-line experience for using Git.
This guide will walk you through setting up Git, using Git Bash, and mastering essential Git commands for local development.
Check out how HOSTINGER HORIZONS can help to build and launch full-stack web apps, tools, and software in minutes without writing any code (Promoted)
Installation
Windows
Download Git for Windows from git-scm.com Run the installer with default options (or customize as needed) Git Bash will be installed automatically as part of the package
macOS
Install Git using Homebrew: brew install git Alternatively, download from git-scm.com
Linux
For Debian/Ubuntu: sudo apt-get install git For Fedora: sudo dnf install git For other distributions, use the appropriate package manager
Verifying Installation
Open Git Bash (Windows) or Terminal (macOS/Linux) and type:
This should display the installed Git version.
[FREE AI Webinar] What truly makes a system "agentic"? Join this deepest / Haystack webinar with Mathis Lucka, Lead AI Engineer, to learn more including a demo of the architecture behind an agent for GitHub actions (April 17, 11:00am ET/ 8:00am PT) [Sponsored]
Git Bash Basics
Git Bash provides a Unix-like shell experience on Windows. Here are some essential commands:
Navigation Commands
pwd – Print working directory ls – List files and directories cd [directory] – Change directory mkdir [directory] – Create a new directory rm [file] – Remove a file rm -r [directory] – Remove a directory and its contents
File Operations
touch [filename] – Create an empty file cat [filename] – Display file contents nano [filename] or vim [filename] – Edit files in the terminal
Keyboard Shortcuts
Ctrl + C – Terminate the current command Ctrl + L – Clear the screen Tab – Auto-complete commands or filenames Up/Down arrows – Navigate through command history
Git Configuration
Before using Git, configure your identity:
Additional Configurations
Set your default editor:
Enable colorful output:
View all configurations:
Basic Git Workflow
Initializing a Repository
Navigate to your project folder and initialize a Git repository:
Checking Status
See which files are tracked, modified, or staged:
Staging Files
Add files to the staging area: