> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Understanding Version Control with Git: Core Concepts

> Discover how Git solves the chaos of manual file versioning and learn the core concepts and everyday commands every developer needs to know.

If you've ever saved files like `script_v2_final_ACTUALLY_FINAL.py`, you already understand the problem Git solves. Version control replaces that messy habit with a proper system that takes clean snapshots of your code over time, remembers exactly who made each change and why, and lets you jump back to any earlier state whenever you need to. Once you start using it, you'll wonder how you ever managed without it.

## The problem Git solves

Imagine working on a Python project. You've probably ended up with something like this:

* `my_script.py`
* `my_script_v2.py`
* `my_script_v2_final.py`
* `my_script_v2_final_ACTUALLY_FINAL.py`
* `my_script_backup_before_breaking_everything.py`

Git solves this mess by tracking changes properly.

## How Git works

Think of Git as taking snapshots of your code:

1. **You write code** — Make changes to your files
2. **You save a snapshot** — Called a "commit" in Git
3. **Git remembers everything** — Every snapshot, who made it, when, and why

```python theme={null}
# Monday: Your code works
def calculate_price(amount):
    return amount * 1.20  # 20% markup

# Tuesday: Boss wants 25% markup
def calculate_price(amount):
    return amount * 1.25  # Changed from 20% to 25%

# Wednesday: "Actually, can we go back to 20%?"
# With Git: Easy! Just go back to Monday's version.
# Without Git: Hope you still have that file somewhere...
```

## Key concepts (all you need)

**Repository (repo)**: A project tracked by Git

* Your `python-for-ai` folder can be a repository

**Staging**: Choosing which changes to save

* Like selecting items to put in a box before shipping

**Commit**: A saved snapshot of your code

* Like saving in a video game — you can always go back

**Push**: Upload your commits to GitHub

* Backs up your code online

**Pull**: Download changes from GitHub

* Get updates when working with others

**Clone**: Copy a project from GitHub

* How you download AI projects to run locally

## First: Install Git

Check whether you already have Git installed:

```bash theme={null}
git --version
```

If you see a version number, you're good to go. If not, follow the instructions for your operating system:

<Tabs>
  <Tab title="Windows">
    1. Download the installer from [git-scm.com](https://git-scm.com/download/win)
    2. Run the installer
    3. Keep all default settings
    4. Restart VS Code after installation
  </Tab>

  <Tab title="macOS">
    **Easiest method (recommended):**

    ```bash theme={null}
    brew install git
    ```

    **Alternative — install Xcode Command Line Tools:**

    ```bash theme={null}
    git --version
    ```

    If Git is not found, macOS will prompt you to install the developer tools. Click **Install** and wait a few minutes.

    Visit [git-scm.com/downloads/mac](https://git-scm.com/downloads/mac) for more options.
  </Tab>

  <Tab title="Linux">
    ```bash theme={null}
    # Ubuntu/Debian
    sudo apt update
    sudo apt install git

    # Fedora
    sudo dnf install git

    # Arch
    sudo pacman -S git
    ```
  </Tab>
</Tabs>

## The simplest Git workflow

Here's all you need to know to get started:

<Note>
  These are terminal commands, not Python code. Run them in VS Code's integrated terminal (Terminal → New Terminal).
</Note>

```bash theme={null}
# 0. First time only — initialize Git in your project folder
git init

# 1. Save your changes locally
git add .
git commit -m "Add price calculation function"

# 2. Upload to GitHub (after connecting — see the next pages)
git push
```

You can run these commands one by one or paste all three at once — the terminal runs them in sequence.

<Warning>
  If you see `fatal: not a git repository`, you need to run `git init` first. This only needs to be done once per project.
</Warning>

## Common questions

<AccordionGroup>
  <Accordion title="Do I need to use the terminal?">
    No! VS Code has a full visual interface for all Git operations. We'll show you both approaches, but you can stick to clicking buttons if you prefer — the result is identical.
  </Accordion>

  <Accordion title="What if I mess up?">
    Git is very forgiving. Every commit is saved permanently, so you can always go back to a working state. It's actually harder to lose work *with* Git than without it.
  </Accordion>

  <Accordion title="Is Git the same as GitHub?">
    No. Git is the tool installed on your computer that tracks changes. GitHub is a website that stores Git projects in the cloud. You can use Git without GitHub, but GitHub makes sharing and backing up your code easy.
  </Accordion>
</AccordionGroup>

## What's next?

Now that you understand the concepts, let's create your GitHub account so you have somewhere to store your code.

<Card title="GitHub setup" icon="github" href="/tools/git/github-setup">
  Create your account in 5 minutes
</Card>
