# What is Git and why servers use it for deploys

> Git is a version control system that records every change to your files as a commit, so a server can fetch an exact version of your code and you can return to any earlier one.

URL: https://levelrail.com/learn/git/what-is-git-and-why-servers-use-it/
Updated: 2026-11-27

Git is a version control system. It stores your project as a series of snapshots called commits, each with a message and a link to the commit before it. Servers and deploy tools use Git because a commit names one exact version of your code. If you deploy commit `a1b2c3d` today and the same commit next week, you get identical files, and if a release breaks something you deploy the previous commit again.

## How it works

A Git repository is a folder with your project files plus a hidden `.git` directory. The `.git` directory holds the whole history. Nothing is stored on a central server unless you choose to add one, so every copy of a repository is a full copy.

Each commit contains:

- A snapshot of every tracked file at that moment.
- The author, the date and a short message you wrote.
- A pointer to the parent commit (the one before it).
- An ID, called a hash, such as `a1b2c3d4e5f6...`. The hash is computed from the content, so changing anything about a commit changes its hash.

Because each commit points to its parent, commits form a chain. That chain is the history. You can read it with `git log`, compare two points with `git diff`, and move your files back to any point in it.

Git also lets the chain split and join. A branch is a movable label that points at a commit, so two people can work on two features at once without touching each other's files. You will build this up over the next lessons in [this track](https://levelrail.com/learn/git/install-and-configure-git/)).

### Commits are snapshots, not file copies

Git does not copy your whole project on every commit. It stores each distinct file version once and reuses it, so a repository with thousands of commits is usually small. You do not need to manage this. What matters is that every commit can be reconstructed completely.

### Local first, shared second

You run `git commit` on your own machine, with no network. Sharing is a separate step: you push commits to a remote repository on a host such as GitHub, GitLab, Gitea or a bare repository on your own server. Other machines, including your servers, fetch from that remote. The lesson on [remotes, push, pull and fetch](https://levelrail.com/learn/git/git-remotes-push-pull-fetch/)) covers it in detail.

## Why servers use Git

Before Git, a typical deploy was `scp` or an FTP upload of files from a laptop. That works until it does not. Someone uploads a file with a local edit nobody committed, forgets one file, or overwrites a newer change. Nobody can say afterwards which version is live.

Pulling from Git fixes four problems:

- **Reproducible deploys.** The server runs one named commit, and the same commit gives the same files every time.
- **Fast rollback.** Every earlier version still exists in history, so going back means checking out an older commit or tag. The [rollbacks lesson](https://levelrail.com/learn/deploy-operate/rollbacks/)) shows how this fits into a real release.
- **A reviewable record.** `git log` says who changed what and when, and the commit message says why.
- **Automation.** A push to a branch can trigger a build and a deploy, which is the idea behind [CI and CD](https://levelrail.com/learn/deploy-operate/what-is-ci-cd/)).

A server rarely needs the whole workflow. Often it needs one thing: read access to the repository, so it can run `git clone` once and `git pull` or `git fetch` plus `git checkout` on every release. You set that up with a read-only [deploy key](https://levelrail.com/learn/git/ssh-keys-and-deploy-keys-for-git/)).

## What Git does not do

Git is built for text files such as source code, config and docs. It handles large binary files and database dumps poorly, because each version of a big file is stored in full. Keep uploads, backups and generated build output out of the repository (see [.gitignore and secrets](https://levelrail.com/learn/git/gitignore-and-keeping-secrets-out-of-git/))).

Git also does not store your [secrets](https://levelrail.com/learn/glossary/#secret)) safely. Anyone who can read the repository can read every file in its history, including files you deleted later. Passwords and API keys belong in [environment variables](https://levelrail.com/learn/deploy-operate/environment-variables-and-secrets/)) or a secrets store, not in commits.

Finally, Git is not a backup. A repository on one disk is as safe as that disk. A remote copy helps, but a [real backup plan](https://levelrail.com/learn/deploy-operate/backups-and-the-3-2-1-rule/)) still covers your data.

A [rollback](https://levelrail.com/learn/glossary/#rollback)) in a Git deploy means going back to an older commit, and servers authenticate with an [SSH key](https://levelrail.com/learn/glossary/#ssh-key)).

## Check it worked

You do not need to install anything to follow this lesson, but you can see whether Git is already on a server:

```bash
git --version
```

If it prints something like `git version 2.43.0`, Git is installed. If the shell says `command not found`, the next lesson installs it. Once you have a repository, `git log --oneline` lists its commits, newest first, each with a short hash and a message.

## Edge cases and gotchas

- **Git is not GitHub.** Git is the tool on your machine. GitHub, GitLab and Gitea are hosts. You can use Git with no host at all, or with a plain SSH server.
- **A commit is permanent in practice.** Even if you delete a file in a later commit, the old version stays in history. Treat anything you commit as published.
- **Short hashes are enough.** You can usually write the first 7 characters of a hash. Git accepts any unique prefix.
- **Staged is not committed.** Changes you added with `git add` are not in history until you run `git commit`. Nothing is saved to history before that.
- **Each clone has full history.** A fresh `git clone` downloads every commit by default. On a server with a very large repository you can ask for less with `git clone --depth 1`, which fetches only the latest snapshot.
- **Commit identity is self-declared.** The name and email on a commit come from your config, and Git does not check them. Signed commits and host-side rules exist for teams that need proof.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `git: command not found` | Git is not installed on this machine | Install it: `sudo apt update && sudo apt install git` |
| `fatal: not a git repository (or any of the parent directories): .git` | You are in a folder with no repository | `cd` into the project, or run `git init` to create one |
| `git log` shows nothing and says `fatal: your current branch 'main' does not have any commits yet` | The repository is new and nothing is committed | Make your first commit (next lessons) |
| `fatal: detected dubious ownership in repository at '/srv/app'` | The folder is owned by another user than the one running Git | Fix ownership with `chown`, or if you trust it, `git config --global --add safe.directory /srv/app` |
| The server runs old code after a deploy | Files were copied by hand, or `git pull` was not run | Pull the intended commit and check `git rev-parse HEAD` on the server |
| `error: Your local changes to the following files would be overwritten by merge` | Someone edited tracked files directly on the server | Stop editing on the server, commit changes elsewhere, and reset the server copy deliberately |

## Quick reference

```bash
git --version              # is Git installed
git log --oneline          # list commits, newest first
git show a1b2c3d           # show one commit
git rev-parse HEAD         # print the full hash you are on
git clone <url>            # download a repository with its history
```

## Related lessons

- [Install and configure Git](https://levelrail.com/learn/git/install-and-configure-git/)): get Git on a server and set your identity.
- [Your first Git repository](https://levelrail.com/learn/git/your-first-git-repository/)): make real commits and read the log.
- [What is CI/CD](https://levelrail.com/learn/deploy-operate/what-is-ci-cd/)): how a push turns into a build and a deploy.
- [Rollbacks](https://levelrail.com/learn/deploy-operate/rollbacks/)): why a known good version makes recovery quick.
- [Environment variables and secrets](https://levelrail.com/learn/deploy-operate/environment-variables-and-secrets/)): where passwords go instead of the repository.

Read more on the blog: [Roll back a failed Docker deploy](https://levelrail.com/blog/rollback-failed-deploy-docker/)) shows the same idea applied to container images.

## Next

Continue with [install and configure Git](https://levelrail.com/learn/git/install-and-configure-git/)) to put Git on your server and set your name and email.

## Frequently asked questions

### What is Git used for?

Git tracks changes to files over time. Developers use it to keep a history of their code, work on features in parallel, and share code through a hosted remote such as GitHub or GitLab.

### What is the difference between Git and GitHub?

Git is the version control tool that runs on your machine. GitHub is a website that hosts Git repositories and adds pull requests, issues and automation on top.

### Why do deploy tools pull from Git?

A Git commit identifies one exact version of the code. Pulling from Git means every deploy uses a known, reviewable version, and rolling back means deploying an older commit.

### Do I need Git to run a server?

No, you can copy files by hand. Git is the common way to avoid mistakes in that process, because the server gets exactly what was committed and nothing else.


## Sources

- [Git documentation](https://git-scm.com/doc)
- [git-commit manual](https://git-scm.com/docs/git-commit)
