{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Version Control\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Notes on Version Control Systems (VCS)\n", "\n", "A **Version Control System** (VCS) is a software tool that helps developers manage changes to their code over time. As you develop software, you make many changes to your codebase. Sometimes, you might need to revisit an earlier version of your code, whether to understand the history of the project, to fix a bug, or to revert an unhelpful change. This is where version control systems come in. They allow you to track the history of your project, understand what changes were made, by whom, and why.\n", "\n", "There are several reasons why version control systems are crucial in software (and web) development:\n", "\n", "- **Collaboration:** Multiple developers can work on the same project without stepping on each other's toes. You can work on your part of the code, and others can work on theirs, without fear of overwriting each other's changes.\n", "\n", "- **Versioning:** You can keep a historical record of all changes made to the project. If you introduce a bug, or if a feature doesn't work as expected, you can always go back to a previous, working version of the code.\n", "\n", "- **Backup:** All the versions of your project are stored safely. If something happens to your local code, you can always retrieve the code from the VCS.\n", "\n", "- **Documentation:** When committing changes to the VCS, developers provide messages explaining why the change was made. This forms a form of documentation that can be helpful to understand the project history and make future decisions.\n", "\n", "There are three types of version control systems:\n", "\n", "1. **Local Version Control Systems:** These systems have a simple database that keeps all the changes to files under revision control.\n", "\n", "2. **Centralized Version Control Systems (CVCS):** These systems contain a single, central repository. Developers get the latest version from the central repository and work on it. Once their changes are complete, they commit the changes to the central repository.\n", "\n", "3. **Distributed Version Control Systems (DVCS):** In this system, every developer has a complete copy of the entire project. This includes all the files, history, and versions. Developers work on their local repository and then push their changes to the central repository.\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Git\n", "\n", "**Git** is one of the most popular Distributed Version Control Systems (DVCS) in use today. Created by Linus Torvalds, the creator of the Linux operating system, Git is a free and open-source tool that is widely used by both individual developers and large corporations. As a DVCS, Git allows every developer to have a complete copy of the entire project, including its history and all versions of every file. This design allows for powerful collaboration features while also providing the ability to work offline.\n", "\n", "Some of the key features of Git are:\n", "\n", "- **Efficiency and Speed:** Git is designed to be fast. No matter the size of your project, you can expect quick operations for committing, branching, merging, and comparing past versions.\n", "\n", "- **Data Integrity:** Git uses a data model that ensures the cryptographic integrity of your projects. Every file and commit is checksummed and retrieved by its checksum when checked back out, which ensures that what you put into Git is precisely what you get out of it.\n", "\n", "- **Non-linear Development:** Git supports rapid branching and merging, and includes specific tools for visualizing and navigating a non-linear development history.\n", "\n", "- **Fully Distributed:** Every Git directory on every computer is a full-fledged repository with a complete history and full version-tracking capabilities, independent of network access or a central server.\n", "\n", "### Explanation of Git's Distributed Version Control System\n", "\n", "In a DVCS like Git, instead of downloading the latest version of the files in the project, you fully clone the repository. This means that if the server containing the central repository goes down, any of the client repositories can be copied back up to the server to restore it. Every clone is a full backup of all the data.\n", "\n", "Furthermore, many operations are local, so they are fast. You have the entire project history, so you don't need to communicate with a server to get the project's history. And if you're working offline or on a plane, you can still commit your changes locally and then upload them to the server when you have connectivity.\n", "\n", "### Installing Git and Setting Up the Development Environment\n", "\n", "To start using Git, you must first install it on your computer. The process of installing Git will depend on your operating system:\n", "\n", "- For **Windows**, you can download Git from [Git for Windows](https://gitforwindows.org/) and then install it. This package also provides the Git Bash command line experience.\n", "\n", "- For **macOS**, you can use the built-in Terminal or install Git with [Homebrew](https://brew.sh/) by running the command `brew install git`.\n", "\n", "- For **Linux**, Git is usually available via your distribution's package manager. For example, on Ubuntu or Debian, you can install Git with `sudo apt-get install git`.\n", "\n", "After installing Git, you should configure it with your personal information. This is important because every Git commit uses this information:\n", "\n", "```bash\n", "git config --global user.name \"Your Name\"\n", "git config --global user.email \"youremail@example.com\"\n", "\n", "```\n", "\n", "### Initializing a New Repository (`git init`)\n", "\n", "To start using Git, you need to initialize a Git repository in your project's directory. This creates a new subdirectory named `.git` that contains all of your necessary repository files — a Git repository skeleton.\n", "\n", "You can do this by navigating to your project's directory in your terminal and running the following command:\n", "\n", "```bash\n", "git init\n", "```\n", "\n", "### Making Changes and Tracking Them (`git add`, `git commit`)\n", "\n", "Once you've initialized a repository, you can start tracking changes to your project. Let's say you've just created a new file named `index.html` for your web development project. To start tracking changes to this file, you need to add it to Git using the `git add` command:\n", "\n", "```bash\n", "git add index.html\n", "```\n", "\n", "The `git add` command takes a path name for either a file or a directory; if it's a directory, the command adds all the files in that directory to staging.\n", "\n", "After you've added your changes, you need to commit them to the Git repository. Commits are like snapshots of your project — they record the state of your project at a specific point in time. To commit your changes, you can use the `git commit` command:\n", "\n", "```bash\n", "git commit -m \"Initial commit\"\n", "```\n", "\n", "The `-m` option allows you to add a message to your commit, which should describe the changes you've made.\n", "\n", "### Viewing the Change History (`git log`)\n", "\n", "Git keeps a history of all the changes you've committed. You can view this history using the `git log` command:\n", "\n", "```bash\n", "git log\n", "```\n", "\n", "This will display a list of all the commits you've made to the repository, starting with the most recent. For each commit, Git displays the commit hash, the author, the date, and the commit message.\n", "\n", "### Practical Example: Developing a Simple Web Page and Tracking Changes with Git\n", "\n", "Let's walk through a practical example. You're developing a simple web page. You start by creating an `index.html` file:\n", "\n", "```html\n", "\n", "\n", "
\n", "