How to use git and git bash locally: a comprehensive guide

Introduction

Git is a distributed version control system that helps you track changes in your code, collaborate with others and maintain a story about your project. Git Bash is a terminal application for Windows that provides a Unix-like command line for use of git.

This guide will guide you through the setup of git, using Git Bash and mastering important Git commands for local development.

Installation

Windows

  1. Download Git to Windows from Git-scm.com
  2. Run the installer with default settings (or customize as needed)
  3. Git Bash is automatically installed as part of the package

Makos

  1. Install Git using Homebrew: Brew Install Git
  2. Alternatively you can download from git-scm.com

Linux

  • For Debian/Ubuntu: Sudo Apt-Bet Install Git
  • To Fedora: Sudo DNF Install Git
  • For other distributions, use the appropriate package handling

Confirmation of the installation

Open Git Bash (Windows) or Terminal (MacOS/Linux) and Type:

This should show the installed git version.

Git Bash Basics

Git Bash provides a unix-like shell experience on Windows. Here are some important commands:

Navigation commands

  • PWD – Print Working Directory
  • LS – List files and folders
  • CD [directory] – Change library
  • Mkdir [directory] – Create a new library
  • RM [file] – Remove a file
  • RM -R [directory] – Remove a library and its contents

File operations

  • touch [filename] – Create an empty file
  • cat [filename] – Show file content
  • Nano [filename] or vim [filename] – Edit files in the terminal

Keyboard shortcuts

  • Ctrl + C – Complete the current command
  • Ctrl + L – Clear the screen
  • Tab-Auto-Completed Commands or File Names
  • Up/down arrows – navigate through command history

Git configuration

Before using Git, configure your identity:

Additional configurations

Set your default editor:

Enable Colorful Output:

See all configurations:

Basic Git work process

Initialization of a depot

Navy to your project folder and initialize a git archive:

Control status

See which files are tracked, changed or staged:

Staging files

Add files to the staging area:

Commits changes

Save staged changes in the depot:

Or open an editor to write a more detailed obligation:

View of committing history

Branching and fusion

Works with branches

Create a new branch:

Switch to a branch:

Create and switch to a new branch in a command:

List of all branches:

Fusion of branches

Fusion changes from another branch to your current branch:

Handling of braid conflicts

When git does not automatically braid changes, resolve conflicts:

  1. Git marks the conflicting files
  2. Open the files and look for conflict markers (<<<<<<, =======, >>>>>>>))
  3. Edit the files to resolve conflicts
  4. Add the Loose File: Git Add
  5. Complete the merger: Git Commit

Deleting branches

Delete a branch after fusion:

Remote warehouses

Adding an external stock

Viewing external warehouses

Pushes to a remote warehouse

Pulling from a remote warehouse

Cloning of a depot

Advanced Git commands

Stashing changes

Temporarily Save Modified Files to Work On Something Other:

Return to changes

Undo oblige:

Reset to a previous mode (use with caution):

Viewing and comparing changes

Interactive Rebase

Rewrite, Squash or Retriction Obligation:

Troubleshooting

Common problems and solutions

Problem: “FATAL: NOT A GIT Repository”

  • Solution: Make sure you are in the correct library or initialize a depot with git init

Problem: Unable to push to remote storage

  • Solution:
    • Check if you have the correct permissions
    • Drag the latest changes first: Git Pull Origin Main
    • Check if external URL is correct: Git External -V

Problem: Braid conflicts

  • Solution: Loose conflicts manually, then add the loose files and git obligation

Problem: Random commitment

  • Solution: Use Git Reset –Soft Head ~ 1 to undo the last obligation while holding changes

Git best practice

  1. Commit often With clear, descriptive obligation notifications
  2. Create branches For new features or bug fixes
  3. Pull before pushing In order to minimize conflicts
  4. Write meaningful obligations It explains why changes were made
  5. Use .Gitignore To exclude unnecessary files (build artifacts, dependencies, etc.)
  6. Review changes Before committing to Git Diff and Git -Status
  7. Keep obligations focused On a single logical change
  8. Use tags For marking releases or important milestones
  9. Back up your storage sites regularly
  10. Documents Your Git work process for team collaboration

.Gitignore Example

Create a .Gitignore file in your depotrod:

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 cross-platforms, important Git Bash commands, initialization of the repository, core add-on-commit work, branching strategies, remote storage management and advanced operations such as stashing and rebasing. We also treated common troubleshooting scenarios and best practices to maintain a clean workflow. With these basic elements, you are now equipped to track changes, collaborate effectively and maintain a structured story about your projects.


Nikhil is an internal consultant at MarkTechpost. He is pursuing an integrated double degree in materials at the Indian Institute of Technology, Kharagpur. Nikhil is an AI/ML enthusiast who always examines applications in fields such as biomaterials and biomedical science. With a strong background in material science, he explores new progress and creates opportunities to contribute.

Leave a Comment