Git & GitHub Tutorial

Rahul's Profile

Git Install

Installation Guide

Windows Install

  • Download the Git installer from git-scm.com
  • Run the installer and follow the default prompts
  • After installation, open Git Bash from the start menu
https://git-scm.com/download/win

Linux Install

Use the package manager specific to your distribution:

sudo apt update && sudo apt install git  # Debian/Ubuntu
sudo dnf install git  # Fedora
sudo pacman -S git  # Arch Linux

MacOs Install

Install Git using Homebrew:

brew install git

Verify the installation:

git --version
git version check - git bash windows

Git Configuration

Configuring Git is essential for tracking authorship, managing branches, and ensuring consistency across repositories. Below are key configurations and why they matter.

Set Your Name and Email

Every Git commit is associated with a user. Setting your name and email ensures correct attribution in repositories.

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

Default Branch

Git defaults to 'master' as its origin branch , but suppose you want to change it to some other origin say 'main', then you need to set your preference accordingly. To set your preferred default branch, run the following command:

git config --global init.defaultBranch main

View Configuration

To see your current Git settings, use:

git config --list

Change Configuration

If you need to modify an existing configuration:

git config --global user.name "New Name"

Configuration Levels: Local, Global, System

Git settings can be applied at different scopes:

  • Local: Affects only the current repository.
  • Global: Applies to all repositories for the current user.
  • System: Applies to all users on the system.

Example configurations:

git config --local user.email "local@example.com"
git config --global user.email "global@example.com"
git config --system user.email "system@example.com"

Verify Specific Configuration

To check configuration settings at different levels:

git config --local --list
git config --global --list
git config --system --list