View on GitHub

SCRATCH PAD

No polish, just pulse

Git - Version Control System

Git is a distributed version control system (VCS) that tracks changes in source code during software development. It allows multiple developers to collaborate efficiently, manage code versions, and revert changes when necessary.


1. What is Git?

Git is a free and open-source distributed version control system designed to handle projects of all sizes efficiently. It helps developers track changes, collaborate with teams, and manage different versions of code.

Key Features:

📖 Related Resources:


2. Git vs Other Version Control Systems

Feature Git (Distributed VCS) SVN (Centralized VCS)
Repository Structure Every user has a full repo Centralized server
Offline Work Fully supports offline commits Limited offline functionality
Branching & Merging Easy and fast Complex and slow
Speed & Performance Faster due to local storage Slower, dependent on server
Security SHA-1 hashing ensures data integrity Less secure

📖 Related Resources:


3. Basic Git Workflow

Step 1: Initialize a Repository

git init

Creates a new Git repository.

Step 2: Clone a Repository

git clone <repository-url>

Copies an existing repository from a remote server.

Step 3: Check Status

git status

Displays changes and the state of the working directory.

Step 4: Add Files to Staging Area

git add <file-name>
git add .  # Adds all files

Prepares files for commit.

Step 5: Commit Changes

git commit -m "Your commit message"

Saves changes to the repository with a message.

Step 6: Push Changes to Remote Repository

git push origin main  # Push to main branch

Uploads local changes to a remote repository.

Step 7: Pull Changes from Remote Repository

git pull origin main

Fetches and merges changes from the remote repository.

📖 Related Resources:


4. Git Branching & Merging

Branches allow developers to work on features independently without affecting the main codebase.

Creating a Branch

git branch feature-branch

Creates a new branch.

Switching to a Branch

git checkout feature-branch

Switches to an existing branch.

Merging Branches

git checkout main
git merge feature-branch

Combines changes from feature-branch into main.

Deleting a Branch

git branch -d feature-branch

Removes a branch after merging.

📖 Related Resources:


5. Git Remote Repositories

Git allows collaboration via remote repositories hosted on platforms like GitHub, GitLab, and Bitbucket.

Add a Remote Repository

git remote add origin <repository-url>

Links a local repository to a remote one.

View Remote Repositories

git remote -v

Lists remote repositories linked to the project.

Fetch Remote Changes

git fetch origin

Retrieves latest changes without merging.

📖 Related Resources:


6. Handling Git Conflicts

Merge conflicts occur when changes from different branches affect the same lines of code.

Steps to Resolve Conflicts:

  1. Identify conflicts using git status.
  2. Manually edit the conflicting files.
  3. Mark the conflict as resolved:
    git add <file-name>
    
  4. Commit the resolution:
    git commit -m "Resolved merge conflict"
    

📖 Related Resources:


7. Git Reverting & Resetting

Undoing Changes (Reset vs Revert vs Checkout)

📖 Related Resources:


8. Git Best Practices

📖 Related Resources: