Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Machine Learning»How to Use Git and Git Bash Locally: A Comprehensive Guide

    How to Use Git and Git Bash Locally: A Comprehensive Guide

    April 1, 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.

    Installation

    Windows

    1. Download Git for Windows from git-scm.com
    2. Run the installer with default options (or customize as needed)
    3. Git Bash will be installed automatically as part of the package

    macOS

    1. Install Git using Homebrew: brew install git
    2. 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.

    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:

    Committing Changes

    Save staged changes to the repository:

    Or open an editor to write a more detailed commit message:

    Viewing Commit History

    Branching and Merging

    Working with Branches

    Create a new branch:

    Switch to a branch:

    Create and switch to a new branch in one command:

    List all branches:

    Merging Branches

    Merge changes from another branch into your current branch:

    Handling Merge Conflicts

    When Git can’t automatically merge changes, you’ll need to resolve conflicts:

    1. Git will mark the conflicted files
    2. Open the files and look for conflict markers (<<<<<<<, =======, >>>>>>>)
    3. Edit the files to resolve conflicts
    4. Add the resolved files: git add <filename>
    5. Complete the merge: git commit

    Deleting Branches

    Delete a branch after merging:

    Remote Repositories

    Adding a Remote Repository

    Viewing Remote Repositories

    Pushing to a Remote Repository

    Pulling from a Remote Repository

    Cloning a Repository

    Advanced Git Commands

    Stashing Changes

    Temporarily store modified files to work on something else:

    Reverting Changes

    Undo commits:

    Reset to a previous state (use with caution):

    Viewing and Comparing Changes

    Interactive Rebase

    Rewrite, squash, or reorder commits:

    Troubleshooting

    Common Issues and Solutions

    Problem: “fatal: not a git repository”

    • Solution: Make sure you’re in the correct directory or initialize a repository with git init

    Problem: Unable to push to remote repository

    • Solution:
      • Check if you have the correct permissions
      • Pull latest changes first: git pull origin main
      • Check if remote URL is correct: git remote -v

    Problem: Merge conflicts

    • Solution: Resolve conflicts manually, then git add the resolved files and git commit

    Problem: Accidental commit

    • Solution: Use git reset –soft HEAD~1 to undo the last commit while keeping changes

    Git Best Practices

    1. Commit frequently with clear, descriptive commit messages
    2. Create branches for new features or bug fixes
    3. Pull before pushing to minimize conflicts
    4. Write meaningful commit messages that explain why changes were made
    5. Use .gitignore to exclude unnecessary files (build artifacts, dependencies, etc.)
    6. Review changes before committing with git diff and git status
    7. Keep commits focused on a single logical change
    8. Use tags for marking releases or important milestones
    9. Back up your repositories regularly
    10. Document your Git workflow for team collaboration

    .gitignore Example

    Create a .gitignore file in your repository root:

    Customize this file according to your project’s specific needs.

    Conclusion

    Git and Git Bash provide powerful tools for version control and collaborative development. In this guide, we covered installation across platforms, essential Git Bash commands, repository initialization, the core add-commit workflow, branching strategies, remote repository management, and advanced operations like stashing and rebasing. We also addressed common troubleshooting scenarios and best practices to maintain a clean workflow. With these fundamentals, you’re now equipped to track changes, collaborate effectively, and maintain a structured history of your projects.

    The post How to Use Git and Git Bash Locally: A Comprehensive Guide appeared first on MarkTechPost.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleMeet ReSearch: A Novel AI Framework that Trains LLMs to Reason with Search via Reinforcement Learning without Using Any Supervised Data on Reasoning Steps
    Next Article Build a Powerful Image Editor with Next.js and glfx.js

    Related Posts

    Machine Learning

    How to Evaluate Jailbreak Methods: A Case Study with the StrongREJECT Benchmark

    July 22, 2025
    Machine Learning

    Boolformer: Symbolic Regression of Logic Functions with Transformers

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Microsoft’s Windows 95 testing phase was so intense that it crashed cash registers with over $10,000 worth of software

    News & Updates

    Adobe adviseert webshops kritiek beveiligingslek binnen 72 uur te patchen

    Security

    A Coding Implementation for Advanced Multi-Head Latent Attention and Fine-Grained Expert Segmentation

    Machine Learning

    CVE-2025-5297 – SourceCodester Computer Store System Stack-Based Buffer Overflow Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-7211 – “Code-Projects LifeStyle Store SQL Injection Vulnerability”

    July 9, 2025

    CVE ID : CVE-2025-7211

    Published : July 9, 2025, 3:15 a.m. | 3 hours, 22 minutes ago

    Description : A vulnerability was found in code-projects LifeStyle Store 1.0. It has been declared as critical. This vulnerability affects unknown code of the file /cart_add.php. The manipulation of the argument ID leads to sql injection. The attack can be initiated remotely. The exploit has been disclosed to the public and may be used.

    Severity: 7.3 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Laravel Performance Testing With Volt-Test PHP

    July 1, 2025

    Senua’s Saga: Hellblade 2 comes to PS5 with “exciting new features,” Xbox and PC getting free update

    May 21, 2025

    CVE-2025-4601: Flaw Exposes 33,000+ RealHomes WordPress Sites to Admin Takeover

    June 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.