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.
- Updated Nov 27, 2026
- Markdown
Explain what a commit is, how Git history works, and why deploys pull from Git instead of copying files by hand.
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.
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 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 shows how this fits into a real release.
- A reviewable record.
git logsays 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.
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.
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).
Git also does not store your secrets 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 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 still covers your data.
A rollback in a Git deploy means going back to an older commit, and servers authenticate with an 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:
git --versionIf 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 addare not in history until you rungit commit. Nothing is saved to history before that. - Each clone has full history. A fresh
git clonedownloads every commit by default. On a server with a very large repository you can ask for less withgit 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#
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 historyRelated lessons#
- Install and configure Git: get Git on a server and set your identity.
- Your first Git repository: make real commits and read the log.
- What is CI/CD: how a push turns into a build and a deploy.
- Rollbacks: why a known good version makes recovery quick.
- Environment variables and secrets: where passwords go instead of the repository.
Read more on the blog: Roll back a failed Docker deploy shows the same idea applied to container images.
Next#
Continue with install and configure Git to put Git on your server and set your name and email.
Check what you learned
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
Keep going: guides and tutorials
- Install a Self-Hosted PaaS on Your Own Server in Five Minutes One installer download, one setup token, one sample app. The full Levelrail install on a fresh Linux server, with the checks and the fixes.
- Deploy a Docker Compose App Self-Hosted: Web, Redis and Rollback Deploy a Docker Compose app on your own server with Levelrail: a web service and Redis, a bad release that does not take traffic, and a compose rollback.