Skip to main content

Basics

Version Control

Version Control is a system that records changes to a file or set of files over time, allowing multiple people to collaborate, track changes, and revert to previous versions when necessary. It is particularly useful in software development to manage code efficiently.

There are two main types of Version Control Systems (VCS):

  1. Centralized Version Control System (CVCS) – A single central repository is used, and all users access this repository (e.g., SVN).
  2. Distributed Version Control System (DVCS) – Each user has a complete copy of the repository, allowing work offline and better collaboration (e.g., Git, Mercurial).

Git is a Distributed Version Control System (DVCS) that enables developers to track code changes, collaborate, and revert to previous versions if needed.

How Version Control Works in Git?

  1. Repository (Repo): A directory containing files and a hidden .git folder that tracks changes.
  2. Commit: A snapshot of changes, allowing you to revert or check previous versions.
  3. Branching: Creating a separate version of the code to work on new features without affecting the main project.
  4. Merging: Integrating changes from different branches.
  5. Remote Repositories: A shared version of the project stored on services like GitHub or GitLab.

Workflow

Working Directory => Staging Areay => Local Repository => Remote Repository
  1. Working Directory
    • where actual files and code exist on local system.
    • when you create/modify files, they remain untracked until you explicityly add them to git
  2. Staging Area
    • pre-commit area, allowing you to review changes before commit
    • it make ready files to make commit
  3. Local Repository
    • when you commit, the changes are stored in local repository
    • local repository keeps track of all commits, branches
  4. Remote Repository
    • share changes with other.
      [Working Directory]  --->  [Staging Area]  --->  [Local Repository]  --->  [Remote Repository]
│ │ │ │
Untracked Prepared for Commit Committed |
│ │ │ │
Modify File git add file git commit -m git push origin main

Configuration

git config is a command used to configure Git settings on your system.

Types of Git Configurations

  1. System Level

    • Applies to all users and repositories on the computer.
    • Stored in: C:\Program Files\Git\etc\gitconfig (Windows).
  2. Global-level

    • Applies to all repositories for the current user.
    • Stored in: ~/.gitconfig or ~/.config/git/config.
  3. Local-level

    • Specific to a single repository.
    • Stored in: .git/config inside the repository.

📌 Note:

  • Local configurations override global configurations.
  • Global configurations override system configurations.

Commands

  1. Setup user information:

    git config --global user.name "John Doe"
    git config --global user.email "john.doe@example.com"
    • user.name: Your name (appears in commit history).
    • user.email: Your email (used for commit identification).
  2. Check Configuration Settings

    git config --list

    Displays user details, editor preferences, merge tools, etc.

To update the data, just reassign the data

For the first time after git configuration, when you want to push some document, you need to login/authenticate your github account